[英]Python Selenium geckodriver required in path
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/ubuntu/bin/python/DLX/geckodriver': '/home/ubuntu/bin/python/DLX/geckodriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 25, in <module>
driver = webdriver.Firefox(executable_path=geckoPath,options=options)
File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
self.service.start()
File "/home/ubuntu/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
The above is the error I am getting while trying to use geckodriver and selenium.以上是我在尝试使用 geckodriver 和 selenium 时遇到的错误。 Geckodriver is in the path /home/ubuntu/bin/python/DLX/, that path has been added to the PATH var and I can see it when using echo $PATH.
Geckodriver 在路径 /home/ubuntu/bin/python/DLX/ 中,该路径已添加到 PATH var 中,我可以在使用 echo $PATH 时看到它。 Below is the code I'm trying to get running.
下面是我试图运行的代码。
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.webdriver import DesiredCapabilities
from sys import platform
# setting browser to be heaadless
options = Options()
options.add_argument("--headless")
#Telling it where to find the required file
currentDir = os.path.dirname(os.path.realpath(__file__))
geckoPath = os.path.realpath(os.path.join(currentDir,'geckodriver'))
print(geckoPath)
binary = FirefoxBinary(geckoPath)
driver = webdriver.Firefox(executable_path=geckoPath,options=options)
I've looked at other posts, tried their fixes and I've still got the issue.我查看了其他帖子,尝试了他们的修复,但我仍然遇到了问题。 Running it on RPI3b+ Ubuntu server if that helps.
如果有帮助,请在 RPI3b+ Ubuntu 服务器上运行它。 Selenium Ver=3.141.0 geckodriver ver=v0.23.0
Selenium Ver=3.141.0 geckodriver ver=v0.23.0
Edit: PATH is as follows /home/ubuntu/.cargo/bin:/home/ubuntu/.local/bin:/home/ubuntu/bin:/home/ubuntu/.cargo/bin:/home/ubuntu/.local/bin:/home/ubuntu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/ubuntu/bin/python/DLX编辑:PATH如下/home/ubuntu/.cargo/bin:/home/ubuntu/.local/bin:/home/ubuntu/bin:/home/ubuntu/.cargo/bin:/home/ubuntu/.local /bin:/home/ubuntu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/游戏:/snap/bin:/home/ubuntu/bin/python/DLX
It would be fine if you create once driver folder in you project and place geckodriver there and provide path as mentioned below.如果您在项目中创建一次驱动程序文件夹并将 geckodriver 放在那里并提供如下所述的路径,那会很好。
Lets say folder name is drivers
假设文件夹名称是
drivers
firefox_driver = "/drivers/geckodriver"
driver = webdriver.Firefox(executable_path=firefox_driver,options=options)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.