python目录名称无效_python - NotADirectoryError:[WinError 267]通过Selenium Python调用Firefox时目录名称无效错误...

我正试图从下面的python代码调用使用Selenium webdriver的firefox浏览器。。from selenium import webdriver

# Initializing the WebDriver for Firefox browser

driver = webdriver.Firefox("C:\\selenium\\mozilla\\geckodriver.exe")

driver.set_page_load_timeout(30)

driver.maximize_window()

driver.get("https://www.google.com/")

# Closing the reference

driver.quit()

但它总是会抛出如下错误,不过这对Chrome浏览器是有效的。

Traceback (most recent call last):

File "C:/Python/Practice/FirefoxSample.py", line 8, in

driver = webdriver.Firefox("C:\\selenium\\mozilla\\geckodriver.exe")

File "C:\Python\venv\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 139, in __init__

firefox_profile = FirefoxProfile(firefox_profile)

File "C:\Python\venv\lib\site-packages\selenium\webdriver\firefox\firefox_profile.py", line 78, in __init__

ignore=shutil.ignore_patterns("parent.lock", "lock", ".parentlock"))

File "C:\Python\Python36-32\lib\shutil.py", line 309, in copytree

names = os.listdir(src)

NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\\selenium\\mozilla\\geckodriver.exe'

Process finished with exit code 1

我错过了什么?

我还尝试使用pip升级selenium包

pip install -U selenium

其他信息:运行firefox最新版本(59.0.2)、python(3.6.5)和selenium gecko webdriver(0.20.0)。不确定是否需要帮助。

最佳答案:

你需要处理以下几件事:

您需要通过一个正斜杠(即\)和原始的(即r开关)传递密钥可执行路径以及壁虎的绝对路径值,如下所示:from selenium import webdriver

driver = webdriver.Firefox(executable_path=r'C:\selenium\mozilla\geckodriver.exe')

driver.set_page_load_timeout(30)

driver.get("https://www.google.com/")

driver.quit()

通过IDE清理项目工作区,并仅使用所需的依赖项重新生成项目。

使用CCleaner工具清除测试套件执行前后的所有操作系统杂务。

如果您的基本Web客户端版本太旧,请通过Revo Uninstaller卸载它,并安装最新的GA和发布的Web客户端版本。

重新启动系统。

执行@Test。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值