Firefox driver can't start for Selenium 3.0.1 with FF49 and Python

拜拜、爱过 提交于 2019-12-13 08:10:13

问题


i have following Selenium Webdriver script with Python. But i got error:

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

error is:

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 version is: 3.0.1
Firefox: 49.0.2
geckodriver: v0.11.1-win64

i added geckodriver path to Windows PATH variable.

where is the problem?


回答1:


You can place the 'geckodriver' .exe in the base path of Python and it will work.

Alternatively, you have to declare the path to geckodriver when initializing if you prefer to have a clean Python folder. Either do it every time you run your script or by PATH as you says you've done. As Naveen suggests, a reboot is necessary before a PATH is correctly saved. You could also try to run this in the Windows command line:

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



回答2:


final code is like follow and working:

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

set path of geckodriver.exe without file name(only folder that it is placed) to PATH vairable.

this time, i have another problem:

driver.close() doesn't close firefox.
when change as driver.quit() it closes but following line is appear on console:

'NoneType' object has no attribute 'path'

there is not any indicator to show it is warning or error. Just line itself.




回答3:


Try to add firefox profile

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


来源:https://stackoverflow.com/questions/40455598/firefox-driver-cant-start-for-selenium-3-0-1-with-ff49-and-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!