4

Trying to run simple code in ubuntu 18.04 to get selenium to start a Firefox webdriver.

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
import time
import traceback

options = Options()
options.headless = True

try:
    print('Trying to create the driver')
    driver = webdriver.Firefox(options=options)
except Exception as e:
    tb = traceback.format_exc()
else:
    try:
        print('Trying to access ubuntu.com')
        driver.get('http://www.ubuntu.com/')
    except Exception as e:
        print(e)
    else:
        time.sleep(10)
        try:
            print('Trying to close the driver')
            driver.close()
            print('Task done')
        except Exception as e:
            print(e)
finally:
    print(tb)

When I run the code as root here is the traceback:

Trying to create the driver
Traceback (most recent call last):
  File "test_sel.py", line 11, in <module>
    driver = webdriver.Firefox(options=options)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
    keep_alive=True)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: connection refused

The output from the geckodriver.log file from the last run of the code is:

1580849922419mozrunner::runnerINFORunning command: "/usr/bin/firefox" "-marionette" "-headless" "-foreground" "-no-remote
" "-profile" "/tmp/rust_mozprofileHprun6"
*** You are running in headless mode.
1580849923532addons.webextension.doh-rollout@mozilla.orgWARNLoading extension '[email protected]': Reading manifest: 
Invalid extension permission: networkStatus
1580849923888addons.webextension.screenshots@mozilla.orgWARNLoading extension '[email protected]': Reading manifest: 
Invalid extension permission: mozillaAddons
1580849923891addons.webextension.screenshots@mozilla.orgWARNLoading extension '[email protected]': Reading manifest: 
Invalid extension permission: telemetry
1580849923892addons.webextension.screenshots@mozilla.orgWARNLoading extension '[email protected]': Reading manifest: 
Invalid extension permission: resource://pdf.js/
1580849923892addons.webextension.screenshots@mozilla.orgWARNLoading extension '[email protected]': Reading manifest: 
Invalid extension permission: about:reader*

My selenium version is 3.14, my geckodriver version is 0.26, my Firefox version is >70, and according to specs I shouldn't see any compatibility issues. geckodriver file is in both the '/usr/local/bin' and my working folders. geckodriver.log and geckodriver both have 777 permissions.

Not sure what to do at this point. Please help.

When the code is ran as non-root the stack trace is:

Trying to create the driver
Traceback (most recent call last):
  File "test_sel.py", line 11, in <module>
    driver = webdriver.Firefox(options=options)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
    keep_alive=True)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: connection refused

And the geckodriver.log says:

1580851603716mozrunner::runnerINFORunning command: "/usr/bin/firefox" "-marionette" "-headless" "-foreground" "-no-remote" 
"-profile" "/tmp/rust_mozprofileCP9aHJ"
*** You are running in headless mode.
1580851605231addons.webextension.doh-rollout@mozilla.orgWARNLoading extension '[email protected]': Reading manifest: In
valid extension permission: networkStatus
1580851605513addons.webextension.screenshots@mozilla.orgWARNLoading extension '[email protected]': Reading manifest: In
valid extension permission: mozillaAddons
1580851605513addons.webextension.screenshots@mozilla.orgWARNLoading extension '[email protected]': Reading manifest: In
valid extension permission: telemetry
1580851605513addons.webextension.screenshots@mozilla.orgWARNLoading extension '[email protected]': Reading manifest: In
valid extension permission: resource://pdf.js/
1580851605513addons.webextension.screenshots@mozilla.orgWARNLoading extension '[email protected]': Reading manifest: In
valid extension permission: about:reader*
JavaScript error: resource://gre/modules/Prompter.jsm, line 437: NS_ERROR_NOT_AVAILABLE: Cannot call openModalWindow on a hidden window
11
  • Update the question with the complete error stack trace. Commented Feb 4, 2020 at 20:31
  • @DebanjanB just added Commented Feb 4, 2020 at 20:50
  • Please don't handcraft the error and error stack trace, publish the complete error. Commented Feb 4, 2020 at 21:11
  • @DebanjanB I'm not sure what you mean. This is the traceback I get when I add in the traceback module, which is the same error without the traceback module. Commented Feb 4, 2020 at 21:16
  • 2
    @DebanjanB thank you. I found what I think is the problem. I work on AWS and I created a new ubuntu server to see if the code would run. I put in python commands line-by-line and created a webdriver instance but then did not close the webdriver at the end and it appears while one port was open I couldn't start another driver instance. I rebooted my server, ran the python commands again, closed the webdriver at the end, and was able to instantiate another webdriver session later. I believe it is important for others to see my solution and so I ask if you could allow me to post my answer. Commented Feb 5, 2020 at 17:46

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.