python目录名称无效怎么处理_NotADirectoryError:[WinError 267]通过Selenium Python调用Firefox时目录名称无效错误...

I'm trying to invoke a firefox browser using Selenium webdriver from below python code..

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()

but it is always throwing an error like below, however this is working for Chrome browser.

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

What am I missing here?

I have also tried upgrading the selenium package using the pip

pip install -U selenium

Additional info: running the Firefox latest version (59.0.2), Python (3.6.5) and Selenium Gecko webdriver (0.20.0). Not sure if anything is needed to help on this.

解决方案

You need to take care of a couple of things as follows :

You need to pass the Key executable_path along with the Value referring to the absolute path of the GeckoDriver through single backslash i.e. \ along with the raw i.e. r switch as follows :

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()

Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.

Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.

If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.

Take a System Reboot.

Execute your @Test.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
NotADirectoryError: [WinError 267 目录名称无效。: 'D:\\shuju\\train\\000001.png' 这个错误是因为你在读取图片,将文件路径设置成了具体到图片文件的位置,而不是文件所在的文件夹。解决办法是将路径设置为图片所在文件夹的路径即可,不需要具体到图片文件位置。 例如,将路径修改为 'D:\\shuju\\train' 就可以解决这个错误。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [NotADirectoryError: [WinError 267] 目录名称无效。: ‘123456.txt](https://blog.csdn.net/weixin_42942135/article/details/113904212)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Selenium WebDriver测试 NotADirectoryError: [WinError 267] 目录名称无效。](https://download.csdn.net/download/weixin_38637884/13741116)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [NotADirectoryError: [WinError 267] 目录名称无效。: ‘img/train_1.png](https://blog.csdn.net/m0_52190506/article/details/121769862)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值