0
votes

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?

4
Looks to be a duplicate of this.MikeJRamsey56
Did you try restarting the machine and run the script?Naveen Kumar R B
you can try printing the path self.path in the line "os.path.basename(self.path)" in service.py and check where the python is looking for the executable (geckodriver.exe)?Naveen Kumar R B

4 Answers

2
votes

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"
0
votes

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.

0
votes

Try to add firefox profile

profile = webdriver.FirefoxProfile()
webdriver.Firefox(capabilities=caps,firefox_profile=profile)
0
votes
from selenium import webdriver

# To Run on FireFox Browser
self.driver = webdriver.Firefox(executable_path="C:/Drivers/geckodriver.exe")

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

print(driver.title)
driver.close()