0

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?

Mahsum Akbas
  • 1,523
  • 3
  • 21
  • 38

4 Answers4

2

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"
MSJ
  • 154
  • 1
  • 3
  • 10
0

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.

Mahsum Akbas
  • 1,523
  • 3
  • 21
  • 38
  • Could you please share your code? It seems that you have an object of no value i.e. `NoneType`. Also, if my answer helped you then mark it as Accepted and create a new question for your new problem. That's how Stack works – MSJ Nov 08 '16 at 08:03
  • 2
    Try to add firefox profile profile = webdriver.FirefoxProfile() webdriver.Firefox(capabilities=caps,firefox_profile=profile) – patricmj Nov 10 '16 at 13:53
  • You should write your comment as an answer, @patricmj, as it'd be more visible that way - and you'd get reputation points for it being the actual solution. – boardrider Nov 20 '16 at 09:51
  • Thanks, I've added a comment with the answer – patricmj Nov 21 '16 at 08:29
0

Try to add firefox profile

profile = webdriver.FirefoxProfile()
webdriver.Firefox(capabilities=caps,firefox_profile=profile)
patricmj
  • 365
  • 2
  • 3
  • 18
0
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()
Peter Badida
  • 11,310
  • 10
  • 44
  • 90
  • 2
    While this code may resolve the OP's issue, it is best to include an explanation as to how your code addresses the OP's issue. In this way, future visitors can learn from your post, and apply it to their own code. SO is not a coding service, but a resource for knowledge. Also, high quality, complete answers are more likely to be upvoted. These features, along with the requirement that all posts are self-contained, are some of the strengths of SO as a platform, that differentiates it from forums. You can edit to add additional info &/or to supplement your explanations with source documentation. – ysf Jun 17 '20 at 18:44