geckodriver icon indicating copy to clipboard operation
geckodriver copied to clipboard

Cannot get GeckoDriver 0.8 to work with Python + Selenium

Open rdhyee opened this issue 10 years ago • 17 comments

Re https://github.com/seleniumhq/selenium/issues/2110. I followed instructions at WebDriver - Mozilla | MDN. My setup:

  • OS X 10.9.5
  • Python 3.5.1 :: Continuum Analytics, Inc.
  • Python module selenium==2.53.5
  • Firefox 47.0
  • 'GeckoDriver 0.8.0`

I downloaded GeckoDriver to `'/Users/raymondyee/bin/geckodriver'. When I run:

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

firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['binary'] = '/Users/raymondyee/bin/geckodriver'

driver = webdriver.Firefox(capabilities=firefox_capabilities)

I eventually get a timeout:

Traceback (most recent call last):
  File "ff_se_test.py", line 8, in <module>
    driver = webdriver.Firefox(capabilities=firefox_capabilities)
  File "/Users/raymondyee/anaconda/envs/myenv3/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 74, in __init__
    keep_alive=True)
  File "/Users/raymondyee/anaconda/envs/myenv3/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 90, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/Users/raymondyee/anaconda/envs/myenv3/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 177, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
  File "/Users/raymondyee/anaconda/envs/myenv3/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "/Users/raymondyee/anaconda/envs/myenv3/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused

Interestingly, the geckodriver.log reports:

Usage:
    /Users/raymondyee/bin/geckodriver [OPTIONS]
/Users/raymondyee/bin/geckodriver: Unknown option --marionette

I might try downgrading to Firefox 46 but I understand that eventually Marionette is required once we go to FF 48.0

rdhyee avatar Jun 14 '16 22:06 rdhyee

firefox_capabilities['binary'] points to the firefox binary itself, not geckodriver. Instead, add the directory where geckodriver lives to your path: os.environ["PATH"] += ":/Users/raymondyee/bin/geckodriver" I found that the python bindings (2.53.2) are still looking for the "wires" executable so I created a symlink from wires -> geckodriver Hope this helps.

I would like there to be a mechanism that didn't require the driver it to be in the path, as this is not necessary for ChromeDriver or IEDriverServer.exe as you can pass their path as an argument when starting the driver.

dbl82 avatar Jun 15 '16 10:06 dbl82

Thanks @dbl82 for helping me figure out that firefox_capabilities['binary'] should point to Firefox itself and not to the geckodriver. I misread the documentation but am glad to see that the Python example has been since updated.

I made the change to firefox_capabilities['binary'], and my code now works.

rdhyee avatar Jun 15 '16 15:06 rdhyee

@rdhyee @dbl82

I updated the instructions on how to use Marionette to reflect that capabilities["binary"] should be the full path to the browser binary.

Thanks for keeping the feedback coming! :+1:

andreastt avatar Jun 15 '16 16:06 andreastt

Hi,

I went through the steps to resolve this issue and I am still getting the same error. I had set a path in my .bash_profile to geckodriver and made sure my script was pointing to the firefox bin. The path I set in .bash_profile is export PATH=PATH$:~/

Any help would be much appreciated!

faustne0 avatar Aug 31 '16 20:08 faustne0

export PATH=PATH$:~/

This will unexport all your other paths. You should read up on the system path, but I suspect you want something akin to:

export PATH=$PATH:/path/to/containing/folder

Then you put the geckodriver binary inside /path/to/containing/folder.

andreastt avatar Sep 01 '16 11:09 andreastt

Ah, sorry my path was unclear, originally I was using: export PATH=$PATH:~/selenium/geckodriver

I just updated it to the full path: export PATH=$PATH:/Users//selenium/geckodriver

I am still getting the same error mentioned in the original issue so I am still unsure what else I am missing.

faustne0 avatar Sep 01 '16 16:09 faustne0

You… haven’t actually said which error you’re getting.

andreastt avatar Sep 01 '16 16:09 andreastt

opps...sorry. The traceback I'm getting is

Traceback (most recent call last): File "/Users/username/PycharmProjects/stuff/FirefoxTest.py", line 19, in driver = webdriver.Firefox(capabilities=caps) File "/Library/Python/2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 65, in init self.service.start() File "/Library/Python/2.7/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: 'wires' executable needs to be in PATH.

Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.del of <selenium.webdriver.firefox.service.Service object at 0x10bda6f90>> ignored

Hope that helps further.

faustne0 avatar Sep 01 '16 16:09 faustne0

Well you appear to have two problems: The Selenium Python binding you’re using appears to look for wires (not geckodriver), and there’s a programming error where some internal code in that binding is trying to access a process attribute on the Service object.

I would suggest using a more recent version, or preferably, installing it from source.

andreastt avatar Sep 01 '16 16:09 andreastt

I had just tried 0.9 and 0.10 with the same traceback errors. How would I go about installing from source. I am still new at this and I do apologize for being annoying but your help is greatly appreciated!

faustne0 avatar Sep 01 '16 17:09 faustne0

As I said in my previous comment, this is a Selenium issue and not a geckodriver issue.

andreastt avatar Sep 01 '16 17:09 andreastt

Ah. ok. I'll take a look into that. Thanks again for the advice!

faustne0 avatar Sep 01 '16 18:09 faustne0

Hi, I am using python 3.5 on Windows 10, and I have a Firefox v49 installed. I have the following items in the PATH variable, in this order: C:\Users\csorn\tools\Firefox C:\Users\csorn\tools\gecko

My sys.path contains these 2 in the fist place: 'C:\Users\csorn\tools\Firefox', 'C:\Users\csorn\tools\gecko'

My gecko folder above contains only wires.exe.

I am still getting WebDriverException: 'geckodriver' executable needs to be in PATH.

(More precisely: Traceback (most recent call last): File "C:\Users\csorn\Anaconda3\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 68, in init self.service.start() File "C:\Users\csorn\Anaconda3\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. )

My code is as simple as below: from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities firefox_capabilities = DesiredCapabilities.FIREFOX firefox_capabilities['marionette'] = True firefox_capabilities['binary'] = 'C:\Users\csorn\tools\Firefox' driver = webdriver.Firefox(capabilities=firefox_capabilities)

Does anybody have any idea, why I am getting this error?

csornaigyula avatar Sep 26 '16 20:09 csornaigyula

@csornaigyula You likely need to upgrade Selenium. geckodriver used to be called “wires”, but it is now called “geckodriver”. It is looking for wires.exe, whereas more recent Selenium versions look for geckodriver.exe.

andreastt avatar Sep 27 '16 13:09 andreastt

Hi Andreas, 1- thanks for the response, and terribly sorry for checking back late. 2- it is most possibly not about version, because as I mentioned I renamed the driver to be wires based on other recommendation, that is a new driver.

Anyway, I will try further.

csornaigyula avatar Oct 09 '16 07:10 csornaigyula

I have issue, kindly helpout me

harshmaur@harshmaur:~/Desktop/scrapynew$ scrapy crawl sh /home/harshmaur/Desktop/scrapynew/scrapynew/spiders/babyoye.py:3: ScrapyDeprecationWarning: Module scrapy.contrib.spiders is deprecated, use scrapy.spiders instead from scrapy.contrib.spiders import CrawlSpider, Rule /home/harshmaur/Desktop/scrapynew/scrapynew/spiders/babyoye.py:4: ScrapyDeprecationWarning: Module scrapy.contrib.linkextractors is deprecated, use scrapy.linkextractors instead from scrapy.contrib.linkextractors import LinkExtractor /home/harshmaur/Desktop/scrapynew/scrapynew/spiders/shopclues_spider.py:3: ScrapyDeprecationWarning: Module scrapy.contrib.linkextractors.sgml is deprecated, use scrapy.linkextractors.sgml instead from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor Traceback (most recent call last): File "/usr/local/bin/scrapy", line 11, in sys.exit(execute()) File "/usr/local/lib/python2.7/dist-packages/scrapy/cmdline.py", line 142, in execute cmd.crawler_process = CrawlerProcess(settings) File "/usr/local/lib/python2.7/dist-packages/scrapy/crawler.py", line 209, in init super(CrawlerProcess, self).init(settings) File "/usr/local/lib/python2.7/dist-packages/scrapy/crawler.py", line 115, in init self.spider_loader = _get_spider_loader(settings) File "/usr/local/lib/python2.7/dist-packages/scrapy/crawler.py", line 296, in _get_spider_loader return loader_cls.from_settings(settings.frozencopy()) File "/usr/local/lib/python2.7/dist-packages/scrapy/spiderloader.py", line 30, in from_settings return cls(settings) File "/usr/local/lib/python2.7/dist-packages/scrapy/spiderloader.py", line 21, in init for module in walk_modules(name): File "/usr/local/lib/python2.7/dist-packages/scrapy/utils/misc.py", line 71, in walk_modules submod = import_module(fullpath) File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module import(name) File "/home/harshmaur/Desktop/scrapynew/scrapynew/spiders/shopcluesselenium.py", line 27, in driver = webdriver.Firefox(capabilities=firefox_capabilities) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 135, in init self.service.start() File "/usr/local/lib/python2.7/dist-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 <bound method Service.del of <selenium.webdriver.firefox.service.Service object at 0x7f92dc9b3c10>> ignored

anujkv avatar Oct 22 '16 07:10 anujkv

I’m locking this conversation as the issue as been resolved and none of the follow-up comments that have been posted have had anything actionable in them.

andreastt avatar Oct 22 '16 09:10 andreastt