使用Selenium 3.5.2,Python3.6打开firefox浏览器

时间:2017-08-24 05:17:23

标签: selenium-webdriver

我安装了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

2 个答案:

答案 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')