Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selenium.common.exceptions.SessionNotCreatedException: Message: Failed to start browser /snap/firefox/current/firefox.launcher

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.

like image 545
Jackk Avatar asked Dec 01 '25 11:12

Jackk


2 Answers

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
like image 54
Hamza Abbad Avatar answered Dec 03 '25 02:12

Hamza Abbad


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.

like image 39
Giuseppe La Gualano Avatar answered Dec 03 '25 00:12

Giuseppe La Gualano



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!