Selenium Firefox配置文件在Linux上丢失

问题描述 投票:0回答:2

我想让Selenium在Ubuntu VM上工作。我有点时间去做。无论我做什么,我总是得到以下对话:

Profile Missing

我不需要特别使用任何配置文件。我最初认为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()

Selenium版本3.141.0

Firefox版本65.0.2

Python版本3.7.2

Linux发行版Ubuntu Budgie 18.04.2 LTS

enter image description here

关于这个问题,确实没有很多信息。我在这做错了什么?

更新:我为每次执行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

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

python selenium selenium-webdriver selenium-firefoxdriver
2个回答
3
投票

看来这个问题与使用Snap而不是Firefox安装apt直接相关。

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

它没有特定的配置文件。

不幸的是,如果您使用内置的软件包管理器安装Firefox,它将通过快照安装。所以要小心,并安装:

sudo apt install firefox

0
投票

似乎直接使用Firefox创建的配置文件将失败。

您可以尝试制作一个复制文件夹并使用它。

至于直接选择配置文件失败的原因,您可以从这里查看详细信息:webdriver.FirefoxProfile(): Is it possible to use a profile without making a copy of it?


0
投票

Geckodriver尝试从/home/username/snap/firefox...的其他目录加载配置文件,因为它未配置为快照安装。如果您仍想使用快照安装,因为它为您提供了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)
© www.soinside.com 2019 - 2024. All rights reserved.