Reputation: 2455
I am trying to get Selenium working on a Ubuntu VM. I'm having a heck of a time doing it to. No matter what I do, I always get the following dialogue:
I do not need to use any profile in particular. I thought initially that Selenium\Gecko creates a temp profile for it's instance. Below are all the things I've tried. Further, I've also tried running as sudo, and\or setting ownership of the profile to nobody
as well as setting the permissions to the profile directory to 777
. None of which proved fruitful. I have seen other SO posts regarding this, none of which have provided me with anything leading to an answer which is obviously why I am here.
# create a new Firefox session
# binary = FirefoxBinary('/snap/bin/firefox')
# binary = FirefoxBinary('/usr/local/bin/geckodriver')
profile = webdriver.FirefoxProfile(profile_directory='/home/jaberwocky/snap/firefox/common/.mozilla/firefox/tm4nraze.selenium')
# profile.set_preference("browser.download.folderList",2)
# profile.set_preference("browser.download.manager.showWhenStarting",False)
# profile.set_preference("browser.download.dir", os.getcwd())
# profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream")
driver = webdriver.Firefox(firefox_profile=profile)
driver.implicitly_wait(20)
driver.get(base_url)
python_button = driver.find_element_by_class_name('sh-hide')
python_button.click()
Selenium Version 3.141.0
Firefox Version 65.0.2
Python Version 3.7.2
Linux Distribution Ubuntu Budgie 18.04.2 LTS
There really isn't a lot of information out there on this problem. What am I doing wrong here?
Update: I found a log file for each execution of gecko. Here is what it shows:
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
/snap/firefox/185/bin/desktop-launch: line 174: /home/addohm/snap/firefox/common/.config/user-dirs.dirs: No such file or directory
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
cp: cannot create regular file '/home/addohm/snap/firefox/common/.config/': Not a directory
/snap/firefox/185/bin/desktop-launch: line 177: /home/addohm/snap/firefox/common/.config/user-dirs.dirs.md5sum: No such file or directory
/snap/firefox/185/bin/desktop-launch: line 177: /home/addohm/snap/firefox/common/.config/user-dirs.locale.md5sum: No such file or directory
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
1551441977454 mozrunner::runner INFO Running command: "/snap/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.kvmA0GU2ZdrC"
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
/snap/firefox/185/bin/desktop-launch: line 174: /home/addohm/snap/firefox/common/.config/user-dirs.dirs: No such file or directory
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
cp: cannot create regular file '/home/addohm/snap/firefox/common/.config/': Not a directory
/snap/firefox/185/bin/desktop-launch: line 177: /home/addohm/snap/firefox/common/.config/user-dirs.dirs.md5sum: No such file or directory
/snap/firefox/185/bin/desktop-launch: line 177: /home/addohm/snap/firefox/common/.config/user-dirs.locale.md5sum: No such file or directory
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/lib/$LIB/liblsp.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
Gtk-Message: Failed to load module "canberra-gtk-module"
Gtk-Message: Failed to load module "canberra-gtk-module"
(firefox:27487): Gtk-WARNING **: Error loading theme icon 'dialog-warning' for stock: Icon 'dialog-warning' not present in theme Pocillo
There is no ~/snap/firefox/common/.config/
but there is a ~/snap/firefox/current/.config/
.
Upvotes: 6
Views: 6196
Reputation: 4787
Geckodriver tries to load the profile from a different directory as /home/username/snap/firefox...
because its not configured to the snap installation. If you still want to use the snap installation, because it gives you features, which the apt installation doesn't provide (like in my case), then you can still do it this way:
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument("-profile")
# put the root directory your default profile path here, you can check it by opening Firefox and then pasting 'about:profiles' into the url field
options.add_argument("/home/username/snap/firefox/common/.mozilla/firefox/dhklfoeb.default-18236362302398")
browser=webdriver.Firefox(options=options)
Upvotes: 7
Reputation: 2455
It seems this issue is directly related to having installed Firefox
using Snap instead of apt
.
Reference: https://ubuntuforums.org/showthread.php?t=2398478
It worked right out of the gate with no specific profile.
Unfortunately if you install Firefox using the in-built software package manager, it will install via snap. So just be careful of that and install with:
sudo apt install firefox
Upvotes: 16
Reputation: 375
It seems that directly use a profile created by Firefox will fail.
You can try to make a copy folder and use it.
As to the reason why directly selecting the profile fails, you can view the details from here: webdriver.FirefoxProfile(): Is it possible to use a profile without making a copy of it?
Upvotes: 0