问题描述
我正在使用 pycharm 和我的 pythn
im using pycharm and my pythn
版本 3.6.7 pip 9.0.1
version 3.6.7 pip 9.0.1
和硒版本 selenium-3.141.0 urllib3-1.24.1
and selenium version selenium-3.141.0 urllib3-1.24.1
我使用这个命令安装 selenium
i install selenium using this commands
pip3 install selenium
然后我就这样编码
from selenium import webdriver
driver = webdriver.Firefox("/home/ghost/automation/pwd/geckodriver")
driver.set_page_load_timeout(30)
driver.get("https://www.google.com/")
driver.maximize_window()
driver.implicitly_wait(120)
driver.get_screenshot_as_file("google.png")
driver.quit()
**当我运行这个时我得到这个错误 **
**when i run this i get this error **
/home/ghost/PycharmProjects/try/venv/bin/python /home/ghost/PycharmProjects/try/open/testcas1.py
Traceback (most recent call last):
File "/home/ghost/PycharmProjects/try/open/testcas1.py", line 3, in <module>
driver = webdriver.Firefox("/home/ghost/automation/pwd/geckodriver")
File "/home/ghost/PycharmProjects/try/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 151, in __init__
firefox_profile = FirefoxProfile(firefox_profile)
File "/home/ghost/PycharmProjects/try/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)
NotADirectoryError: [Errno 20] Not a directory: '/home/ghost/automation/pwd/geckodriver'
Process finished with exit code 1
在这一行 driver = webdriver.Firefox("/home/ghost/automation/pwd/geckodriver")
我的 geckodriver
的正确路径和我的 壁虎驱动版本为 0.23.0
and in this line driver = webdriver.Firefox("/home/ghost/automation/pwd/geckodriver")
its correct path of my geckodriver
nd my geckodriver version is 0.23.0
这些答案对我没有帮助
https://stackoverflow.com/a/40399367/8337986https://stackoverflow.com/a/42945346/8337986
推荐答案
In Brief
需要使用param键executable_path
在使用 GeckoDriver、Firefox 和 Selenium 时,您需要使用 Key executable_path
和 Value 设置为 GeckoDriver 的绝对路径,在单引号内,即 '...'
带正斜杠,即 /
作为路径分隔符如下:
While working with GeckoDriver, Firefox and Selenium, you need to use the Key executable_path
and the Value set to the absolute path of the GeckoDriver within single quotes i.e. '...'
with forward slash i.e. /
as path separator as follows:
driver = webdriver.Firefox(executable_path='/home/ghost/automation/pwd/geckodriver')
或使用默认位置
driver = webdriver.Firefox(executable_path=GeckoDriverManager(cache_valid_range=1).install())
这篇关于NotADirectoryError:[Errno 20] 不是目录:“/home/ghost/automation/pwd/geckodriver"与 GeckoDrriver Firefox 和 Selenium 使用 Python3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!