【发布时间】:2022-10-25 10:05:30
【问题描述】:
我最近升级了 lubuntu 22.04,它希望从 snap 存储库中安装一些东西。火狐就是其中之一。目前我正在使用 Selenium 4.1.3、Python 3.10 和 Firefox 99.0.1 以及最新的 geckodriver V31.0
我一直在使用这个 python3 代码进行测试,但现在它完全无法启动。
首先它没有找到一个配置文件,所以我在里面强制了一些东西:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
options = Options()
options.add_argument("-profile /path2temp/") # create profile
options.set_preference("browser.download.folderList", 2)
options.set_preference("browser.download.manager.showWhenStarting",
False)
options.set_preference("browser.download.dir", "./data_export")
options.set_preference(
"browser.helperApps.neverAsk.saveToDisk",
"application/vnd.google-earth.kml+xml,application/x-zip-compressed,application/gpx+xml,text/csv"
)
options.set_preference("devtools.debugger.remote-enabled", True)
options.set_preference("devtools.debugger.prompt-connection", False)
browser = webdriver.Firefox(options=options, executable_path=r"/usr/bin/geckodriver")
url = 'https://cnn.com'
browser.get(url)
如果 Firefox 已打开,则无法与其通信。通常在过去它只会打开一个新标签并开始工作。但现在我得到这个错误:
Firefox 已经在运行,但没有响应。要使用 Firefox,您 必须首先关闭现有的 Firefox 进程,重新启动您的设备,或者 使用不同的配置文件。
如果我让它启动应用程序,它会在很长时间后超时并出现以下错误(注意,/path2temp/ 是它具有权限的目录的真实路径)。
1651528082918 geckodriver INFO Listening on 127.0.0.1:54985 1651528083062 mozrunner::runner INFO Running command: "/snap/bin/firefox" "--marionette" "-profile /path2temp/" "--remote-debugging-port" "47927" "-- remote-allow-hosts" "localhost" "-no-remote" ATTENTION: default value of option mesa_glthread overridden by environment. ATTENTION: default value of option mesa_glthread overridden by environment. ATTENTION: default value of option mesa_glthread overridden by environment. ATTENTION: default value of option mesa_glthread overridden by environment. DevTools listening on ws://localhost:47927/devtools/browser/19a59834-6a4b-4d75-902c-06c36704d50e Exiting due to channel error. Exiting due to channel error. Exiting due to channel error. Exiting due to channel error. Exiting due to channel error.关于我可以做些什么来解决这个问题的任何想法?
编辑:通过将它传递给位于快照文件结构/home/username/snap/firefox/common/.mozilla/firefox/wnrrbapq.default-中的当前用户配置文件,我至少能够在它启动firefox时让它工作发布
但这不是一个理想的行为,因为我每次都必须关闭浏览器进行测试。
【问题讨论】:
标签: selenium-webdriver firefox