我正在尝试让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()
硒版本 3.141.0
Firefox版本 65.0.2
Python版本 3.7.2
Linux发行版 Ubuntu Budgie 18.04.2 LTS
关于这个问题,实际上没有很多信息。我在这里做什么错了?
更新: 我为每次壁虎的执行找到了一个日志文件。显示的内容如下:
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/
。
答案 0 :(得分:2)
似乎此问题与使用Snap而非Firefox
安装了apt
有关。
参考:https://ubuntuforums.org/showthread.php?t=2398478
它没有特定配置文件就可以正常工作。
不幸的是,如果您使用内置软件包管理器安装Firefox,它将通过snap安装。因此,请小心并安装:
sudo apt install firefox
答案 1 :(得分:1)
似乎直接使用Firefox创建的配置文件会失败。
您可以尝试制作一个副本文件夹并使用它。
关于直接选择配置文件失败的原因,您可以从此处查看详细信息: webdriver.FirefoxProfile(): Is it possible to use a profile without making a copy of it?
答案 2 :(得分:0)
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)