0

I am trying this code:

from selenium import webdriver

browser = webdriver.Firefox()
browser.get('http://seleniumhq.org/')

It opens firefox but does not get the link and shows this message:

Traceback (most recent call last):
  File "new.py", line 3, in <module>
    browser = webdriver.Firefox()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
    keep_alive=True)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 156, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 245, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 314, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused

Configuration:

  • selenium latest version
  • browser latest version
  • python 2.7.14
  • os:kali linux 2.0

geckodriver log:

1527001787163   geckodriver INFO    geckodriver 0.20.1
1527001787169   geckodriver INFO    Listening on 127.0.0.1:51383
1527001788204   mozrunner::runner   INFO    Running command: "/usr/bin/firefox" "-marionette" "-profile" "/tmp/rust_mozprofile.IKjgvyUQaThG"
1527001790297   Marionette  INFO    Listening on port 2828

[problem]

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
tanzid
  • 1
  • 3

3 Answers3

0

This error message...

selenium.common.exceptions.WebDriverException: Message: connection refused

...implies that WebDriverException which is the base webdriver exception was raised as the driver failed to start its internal server to communicate with the python client.

Though you mentioned about selenium latest version and browser latest version, the exact details would have helped us to diagnose the issue in a much easier way.

Again, though you mentioned the message but I don't see any error in geckodriver log.

Try the following steps :

  • Pass the Key executable_path along with the Value referring to the absolute path of the GeckoDriver as follows :

    from selenium import webdriver
    
    browser = webdriver.Firefox(executable_path='/path/to/geckodriver')
    browser.get('http://seleniumhq.org/')
    
  • Upgrade Selenium to current levels Version 3.12.0.

  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
  • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Execute your @Test.
  • Presumably, there was an instance of GeckoDriver and Firefox Browser Client active previously, so always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

You can find a detailed discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

You can try this code :

from selenium import webdriver
driver = webdriver.Firefox(executable_path = r'you web driver full path')
driver.get("http://seleniumhq.org/")
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
0

You need to kill all firefox processes to release the resources.

Add this line to kill.sh

kill $(ps aux | awk '/firefox/ {print $2}')

run

sh kill.sh
Terry Lin
  • 2,529
  • 22
  • 21