我安装了python 3.6和selenium 3.5.2版本,geckodriver.exe。但是当我使用下面的代码无法打开火狐时
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
driver=webdriver.Firefox("C:\\Users\\Desktop\\Selenium\\seleniumfirefoxdriver\\geckodriver.exe")
driver.set_page_load_timeout(20)
driver.get("www.google.com")`enter code here`
driver.maximize_window()
driver.implicitly_wait(20)
NotADirectory Error:
[Win Error 267] The directory name is invalid: C:\\Users\\Desktop\\Selenium\\selenium firefoxdriver\\geckodriver.exe
答案 0 :(得分:0)
尝试以下代码 -
driver = webdriver.Firefox(executable_path=r'C:\Users\Desktop\Selenium\seleniumfirefoxdriver\geckodriver.exe')
如果文件夹名称'selenium firefoxdriver'中有空格,请将该文件夹重命名为'seleniumfirefoxdriver'
答案 1 :(得分:0)
尝试单斜杠和文件夹名称不包含空格使用_或删除文件夹名称“selenium firefoxdriver”中的空格。将其设为“selenium_firefoxdriver”或“SeleniumFirefoxdriver”。
然后使用此代码:
driver = webdriver.Firefox(executable_path=r'C:/Users/Desktop/Selenium/selenium_firefoxdriver/geckodriver.exe')
或
driver = webdriver.Firefox(executable_path=r'C:/Users/Desktop/Selenium/SeleniumFirefoxdriver/geckodriver.exe')