Firefox驱动程序无法为带有FF49和Python的Selenium 3.0.1启动

2024-05-18 04:26:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我用Python编写了以下Selenium Webdriver脚本。但我有个错误:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

caps = DesiredCapabilities.FIREFOX
caps["marionette"] = True
driver = webdriver.Firefox(capabilities=caps)

driver.get("http://www.mahsumakbas.net")

print driver.title

driver.close()

错误是:

Traceback (most recent call last): File "C:\Mahsum\DevelopmentWorkSpace\Eclipse\Java\selenium_proj\src\hello.py", line 6, in driver = webdriver.Firefox(capabilities=caps) File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 135, in init self.service.start() File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

Exception AttributeError: "'Service' object has no attribute 'process'" in > ignored

Selenium Webdriver版本为:3.0.1
火狐:49.0.2
壁虎:v0.11.1-win64

我将geckodriver path添加到Windows path变量中。在

问题出在哪里?在


Tags: pathinpyselfdriverseleniumlinecommon
3条回答

你可以把geckodriver.exe放在Python的基本路径中,它就可以工作了。在

或者,如果您希望有一个干净的Python文件夹,那么在初始化时必须声明geckodriver的路径。或者每次运行脚本时都这样做,或者按照您所说的那样按路径执行。正如Naveen建议的,在正确保存路径之前需要重新启动。您也可以尝试在Windows命令行中运行:

setx path "%path%;c:\path\to\geckodriver-folder"

尝试添加firefox配置文件

profile = webdriver.FirefoxProfile()
webdriver.Firefox(capabilities=caps,firefox_profile=profile)

最终代码如下:

binary = FirefoxBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe")
driver = webdriver.Firefox(firefox_binary=binary)

设置路径壁虎.exe没有文件名(只有它所在的文件夹)到路径VARIABLE。在

这次,我有另一个问题:

司机。关门()不关闭firefox。
当变化为司机。退出()它关闭,但控制台上显示以下行:

'NoneType' object has no attribute 'path'

没有任何指示器显示警告或错误。只需排队。在

相关问题 更多 >