Linux 上缺少 Selenium Firefox 配置文件

Jab*_*cky 3 python selenium selenium-firefoxdriver selenium-webdriver

我正在尝试让 Selenium 在 Ubuntu VM 上工作。我有很多时间这样做。无论我做什么,我总是得到以下对话:

资料缺失

我不需要特别使用任何配置文件。我最初认为 Selenium\Gecko 为其实例创建了一个临时配置文件。以下是我尝试过的所有事情。此外,我还尝试以 sudo 身份运行,并且\或将配置文件的所有权设置nobody为 以及将配置文件目录的权限设置为777. 没有一个被证明是富有成效的。我看过其他关于此的 SO 帖子,但没有一个帖子为我提供了任何导致答案的信息,这显然是我在这里的原因。

# 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()
Run Code Online (Sandbox Code Playgroud)

硒版本3.141.0

火狐版本65.0.2

Python 版本3.7.2

Linux 发行版 Ubuntu Budgie 18.04.2 LTS

在此处输入图片说明

关于这个问题的信息真的不多。我在这里做错了什么?

更新: 我为每次执行 Gecko 找到了一个日志文件。这是它显示的内容:

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
Run Code Online (Sandbox Code Playgroud)

没有,~/snap/firefox/common/.config/但有一个~/snap/firefox/current/.config/

Jab*_*cky 10

这个问题似乎与Firefox使用 Snap 而不是apt.

参考:https : //ubuntuforums.org/showthread.php?t=2398478

它从一开始就可以正常工作,没有特定的配置文件。

不幸的是,如果您使用内置软件包管理器安装 Firefox,它将通过 snap 安装。所以请注意这一点并安装:

sudo apt install firefox
Run Code Online (Sandbox Code Playgroud)


sai*_*tam 7

Geckodriver 尝试从不同的目录加载配置文件,/home/username/snap/firefox...因为它未配置为快照安装。如果您仍然想使用 snap 安装,因为它为您提供了 apt 安装不提供的功能(就像我的情况),那么您仍然可以这样做:

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)
Run Code Online (Sandbox Code Playgroud)