我有ubuntu运行在termux,我安装pycharm创建python代码。问题是我有一些错误打开webdriver。
我有最新的火狐(v59.0.2), selenium 壁虎v.0.24.0和使用Python 3.6.5
这是密码
from selenium import webdriver
driver = webdriver.Firefox('/root/Downloads/geckodriver')
此处为错误
Traceback (most recent call last):
File "<input>", line 3, in <module>
File "/root/PycharmProjects/untitled/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 151, in __init__
firefox_profile = FirefoxProfile(firefox_profile)
File "/root/PycharmProjects/untitled/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/firefox_profile.py", line 80, in __init__
ignore=shutil.ignore_patterns("parent.lock", "lock", ".parentlock"))
File "/usr/lib/python3.6/shutil.py", line 309, in copytree
names = os.listdir(src)
FileNotFoundError: [Errno 2] No such file or directory: '/root/Downloads/geckodriver'
如果我这么做
from selenium import webdriver
driver = webdriver.Firefox(executable_path='/root/Downloads/geckodriver')
此处为错误
Traceback (most recent call last):
File "/root/PycharmProjects/untitled/venv/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/root/Downloads/geckodriver': '/root/Downloads/geckodriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<input>", line 3, in <module>
File "/root/PycharmProjects/untitled/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
self.service.start()
File "/root/PycharmProjects/untitled/venv/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.
2条答案
按热度按时间vaj7vani1#
根据您的第一次代码试用,此错误消息...
...表示您的程序无法在上述目录中找到GeckoDriver。
您可以在讨论FileNotFoundError中找到有关此错误的详细分析:[Errno 2]没有这样的文件或目录:“壁虎司机”:在MAC操作系统中使用GeckoDriver和Python的“geckodriver”
根据您的第二次代码试用,此错误消息...
...表示您的程序无法在上述目录中找到GeckoDriver。
您可以在讨论WebDriverException中找到有关此错误的详细分析:'geckodriver'可执行文件需要在PATH中,即使它是
溶液
理想情况下,您需要:
@Tests
。46scxncf2#
只需将geckodriver文件复制到您的PATH中。键入echo $PATH查找您的PATH