skip to Main Content

I am trying to open Firefox with this simple program in python, I am using the latest version of Ubuntu.

from selenium import webdriver

brow = webdriver.Firefox()

But I am getting the error message,
"selenium.common.exceptions.SessionNotCreatedException: Message: Failed to start browser /snap/firefox/current/firefox.launcher: no such file or directory"

I have tried updating firefox and using a different geckodriver.

2

Answers


  1. Surely you should take a good look at the paths you enter, however, i recommend a generic approach.

    You can use a webdriver-manager that takes care of any problems in this respect automatically and in any supported operating system

    from selenium import webdriver
    from webdriver_manager.firefox import GeckoDriverManager
    
    driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
    

    N.B.: this is compatible with Selenium 4.x and below.

    Login or Signup to reply.
  2. The error is most likely a bug in GeckoDriver causing it to try to find Firefox inside Snap instead of the default location /usr/bin/firefox, because the script has been run from PyCharm that was installed through Snap.

    To solve the issue, you have to unset the Snap environment variables before running the script. Actually, I found out that only two variables must be unset: SNAP_NAME and SNAP_INSTANCE_NAME:

    $ unset SNAP_NAME
    $ unset SNAP_INSTANCE_NAME
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search