0
votes

I have written a basic script which tries to open a website with Selenium(webdriver).

Here is my script:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("https://google.com")

driver.quit()

When I launch the above script the Firefox browser pops-up, however it remains blank and it does not navigate to the mentioned website(in this case Google)? I do get an error on terminal screen:

Traceback (most recent call last): File "test.py", line 10, in driver = webdriver.Firefox() File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 158, in init keep_alive=True) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in init self.start_session(desired_capabilities, browser_profile) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute self.error_handler.check_response(response) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: connection refused

Here is the geckodriver log file contents:

1513507080726 geckodriver INFO geckodriver 0.19.1 1513507080735 geckodriver INFO Listening on 127.0.0.1:47815 1513507081261 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-profile" "/tmp/rust_mozprofile.IaZFxa8B0Ir8" 1513507085202 Marionette ERROR Error on starting server: [Exception... "Component returned failure code: 0x804b0036 (NS_ERROR_SOCKET_ADDRESS_IN_USE) [nsIServerSocket.initSpecialConnection]" nsresult: "0x804b0036 (NS_ERROR_SOCKET_ADDRESS_IN_USE)" location: "JS frame :: chrome://marionette/content/server.js :: MarionetteServer.prototype.start :: line 95" data: no] [Exception... "Component returned failure code: 0x804b0036 (NS_ERROR_SOCKET_ADDRESS_IN_USE) [nsIServerSocket.initSpecialConnection]" nsresult: "0x804b0036 (NS_ERROR_SOCKET_ADDRESS_IN_USE)" location: "JS frame :: chrome://marionette/content/server.js :: MarionetteServer.prototype.start :: line 95" data: no] MarionetteServer.prototype.start@chrome://marionette/content/server.js:95:19 MarionetteComponent.prototype.init@resource://gre/components/marionette.js:217:5 MarionetteComponent.prototype.handle@resource://gre/components/marionette.js:112:5

I have no idea what is going on here, I can't seem to figure out how to fix this error? Do you guys have any idea, how this error can be fixed and what is causing this?

2

2 Answers

0
votes

As you are using geckodriver 0.19.1 use the latest Selenium v3.8.1 along with latest Firefox Quantum Web Browser.

Finally, when you initialize the webdriver, instead of driver = webdriver.Firefox() try with :

driver = webdriver.Firefox(executable_path="/path/to/geckodriver")
0
votes

Browser and its selenium driver must be matched in version.

Refer to geckodriver release page to get the right release of driver you want. Chrome webdriver is also a good choice.

The exception selenium.common.exceptions.WebDriverException: Message: connection refused is usually caused by driver mismatch with the browser.