Firefox 使用 webdriver python API 时无法打开 url

     2023-03-12     90

关键词:

【中文标题】Firefox 使用 webdriver python API 时无法打开 url【英文标题】:Firefox fails to open url when using webdriver python API 【发布时间】:2021-09-04 10:17:51 【问题描述】:

我是 python 新手,正在尝试构建一个 selenium 代码来通过 firefox 打开一个网站。 我正在使用 debian 拉伸机进行测试。工具的版本如下:

geckodriver 0.24.0 (2019-01-28) , Python 2.7.13 , Mozilla Firefox 52.7.3 , selenium (3.141.0)

我看到 firefox 窗口打开了(即使是无头的)。但它并没有进一步打开网站。 firefox 实例在打开后等待一段时间然后停止,脚本给出类似的错误

WebHandle.open_application("Firefox" , "http://www.google.com") 文件“/home/yyyyy/yyyyy/yyyyy/yyyyy/script.py”,第 49 行,在 open_application driver = webdriver.Firefox(firefox_options = options, executable_path='/usr/local/bin/geckodriver') init 中的文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py”,第 174 行 keep_alive=真) init 中的文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py”,第 157 行 self.start_session(功能,浏览器配置文件) 文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py”,第 252 行,在 start_session 响应 = self.execute(Command.NEW_SESSION,参数) 文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py”,第 321 行,在执行 self.error_handler.check_response(响应) 文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py”,第 242 行,在 check_response 引发异常类(消息、屏幕、堆栈跟踪) selenium.common.exceptions.WebDriverException:消息:连接被拒绝

代码:

from selenium import webdriver
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options as FirefoxOptions

        options = FirefoxOptions()
        options.add_argument("--headless")
        print (" * Opening firefox session")
        driver = webdriver.Firefox(firefox_options = options, executable_path='/usr/local/bin/geckodriver')
        driver.get("https://www.google.com")
        driver.maximize_window()
        print(driver.title)

查看 geckodriver.log 时,我看到以下错误

1624193615192 mozrunner::runner INFO 运行命令:“/usr/bin/firefox”“-marionette”“--headless”“-foreground”“-no-remote”“-profile”“/tmp/rust_mozprofile.Wwi0327B9dAL " 1624193616996 Marionette INFO 监听 2828 端口

[孩子 28357] ###!!!中止:通道错误中止。:文件 /build/firefox-esr-52.7.3esr/ipc/glue/MessageChannel.cpp,第 2152 行 [孩子 28357] ###!!!中止:通道错误中止。:文件 /build/firefox-esr-52.7.3esr/ipc/glue/MessageChannel.cpp,第 2152 行

###!!! [Child][MessageChannel] 错误:(msgtype=0x3E0003,name=PCompositable::Msg_Destroy) 通道错误:无法发送/接收 ###!!! [Child][MessageChannel] 错误:(msgtype=0x3E0003,name=PCompositable::Msg_Destroy) 频道错误:无法发送/接收

感谢您在解决问题方面提供的任何帮助

【问题讨论】:

【参考方案1】:

尝试将geckodriver.exe 文件放在单独的文件夹和驱动器中,并更新executable_path 中的路径。 例如:

driver = webdriver.Firefox(firefox_options = options, executable_path=r"D:/Python/drivers/geckodriver.exe")

【讨论】:

使用 selenium-webdriver/firefox (NodeJS) 设置 userAgent

】使用selenium-webdriver/firefox(NodeJS)设置userAgent【英文标题】:SetuserAgentwithselenium-webdriver/firefox(NodeJS)【发布时间】:2017-03-1220:21:25【问题描述】:我有一个使用“selenium-webdriver”运行浏览器的代码。它在Ubuntu上运行。我必须重写use... 查看详情

在 Python 的 Selenium webdriver 中使用带有无头 firefox 的 http 代理

】在Python的Seleniumwebdriver中使用带有无头firefox的http代理【英文标题】:UsingahttpproxywithheadlessfirefoxinSeleniumwebdriverinPython【发布时间】:2018-06-1105:18:00【问题描述】:我正在使用这样的无头Firefox:fromselenium.webdriver.firefox.firefox_binary... 查看详情

用于 Firefox 的 Selenium WebDriver [重复]

】用于Firefox的SeleniumWebDriver[重复]【英文标题】:SeleniumWebDriverforFirefox[duplicate]【发布时间】:2016-10-2112:34:31【问题描述】:我对SeleniumWebDriver有一些问题。我正在使用最新的firefox版本(47.0)并绑定使用最后一个Selenium-Server-standa... 查看详情

Firefox Webdriver 非常慢

】FirefoxWebdriver非常慢【英文标题】:FirefoxWebdriverisextremelyslow【发布时间】:2016-01-0918:46:36【问题描述】:我们使用seleniumwebdriverdll设置来运行我的自动化套件。仅在Firefox中运行测试时遇到此问题。Firefox中的测试运行速度非常慢... 查看详情

使用 Selenium Webdriver 和 FireFox 时出错

】使用SeleniumWebdriver和FireFox时出错【英文标题】:ErrorusingSeleniumWebdriverandFireFox【发布时间】:2016-11-0716:30:39【问题描述】:“浏览器似乎已退出”selenium.common.exceptions.WebDriverException:消息:浏览器似乎在我们连接之前已经退出... 查看详情

selenium webdriver.firefox()错误[重复]

】seleniumwebdriver.firefox()错误[重复]【英文标题】:seleniumwebdriver.firefox()Error[duplicate]【发布时间】:2017-07-2202:45:52【问题描述】:我正在尝试使用selenium启动googlechrome,但出现错误这是我的代码:fromseleniumimportwebdriverbrowser=webdriv... 查看详情

在 Python 中使用 Selenium WebDriver 时处理 Firefox 无响应?

】在Python中使用SeleniumWebDriver时处理Firefox无响应?【英文标题】:HandleFirefoxNotRespondingWhileUsingSeleniumWebDriverWithPython?【发布时间】:2014-04-1523:53:01【问题描述】:我正在使用Selenium和Python来测试网络应用程序;但是,Firefox会定期... 查看详情

Firefox 使用 webdriver python API 时无法打开 url

】Firefox使用webdriverpythonAPI时无法打开url【英文标题】:FirefoxfailstoopenurlwhenusingwebdriverpythonAPI【发布时间】:2021-09-0410:17:51【问题描述】:我是python新手,正在尝试构建一个selenium代码来通过firefox打开一个网站。我正在使用debian... 查看详情

如何隐藏 Firefox 窗口(Selenium WebDriver)?

】如何隐藏Firefox窗口(SeleniumWebDriver)?【英文标题】:HowtohideFirefoxwindow(SeleniumWebDriver)?【发布时间】:2011-07-1906:01:34【问题描述】:当我同时执行多个测试时,我不想让Firefox浏览器窗口保持可见。我可以使用selenium.minimizeWindow... 查看详情

无法使用 C# 在 Selenium WebDriver 中使用现有的 Firefox 配置文件

】无法使用C#在SeleniumWebDriver中使用现有的Firefox配置文件【英文标题】:Can\'tuseexistingFirefoxprofileinSeleniumWebDriverusingC#【发布时间】:2018-03-2201:04:33【问题描述】:我需要为Firefox使用共享配置文件,该配置文件在退出时不会被删除... 查看详情

使用 Selenium WebDriver for Firefox 下载 pdf

】使用SeleniumWebDriverforFirefox下载pdf【英文标题】:DownloadingpdfwithSeleniumWebDriverforFirefox【发布时间】:2018-03-0805:44:56【问题描述】:我正在尝试将.pdf下载到我的本地,以便我可以使用ApachePDFBox从中读取文本并将其验证为我的测试... 查看详情

如何在 Firefox 58++ 上使用 PHP Webdriver for Selenium 下载文件

】如何在Firefox58++上使用PHPWebdriverforSelenium下载文件【英文标题】:HowtodownloadafilewiththePHPWebdriverforSeleniumonFirefox58++【发布时间】:2018-05-1721:07:50【问题描述】:我一直在尝试使用Selenium的PHPWebdriver下载最新版本的Firefox文件,但我... 查看详情

无法使用 java 在 firefox 上的 selenium webdriver 中处理警报

】无法使用java在firefox上的seleniumwebdriver中处理警报【英文标题】:Unabletohandlealertsinseleniumwebdriveronfirefoxusingjava【发布时间】:2019-10-2911:01:45【问题描述】:当我登录我的网站时,会弹出一个警报“您是否允许MyWeb向您发送通知”... 查看详情

Selenium WebDriver 无法与 Firefox 20 连接

】SeleniumWebDriver无法与Firefox20连接【英文标题】:SeleniumWebDriverdoesnotconnectwithFirefox20【发布时间】:2013-03-2617:35:52【问题描述】:我正在使用selenium-server-standalone-2.28.0.jar。推出枢纽和使用以下命令启动监听器"C:\\ProgramFiles(x86)\\Java... 查看详情

Python + Selenium firefox webdriver - 从网站中提取图像

】Python+Seleniumfirefoxwebdriver-从网站中提取图像【英文标题】:Python+Seleniumfirefoxwebdriver-pullingoutimagesoutofawebsite【发布时间】:2018-03-0223:59:53【问题描述】:我正在尝试使用以下方法从网页中提取图像:Python2.7+Selenium(使用FireFox)+B... 查看详情

在 Webdriver 中提交表单后如何等待页面加载。我正在使用 Firefox 驱动程序

】在Webdriver中提交表单后如何等待页面加载。我正在使用Firefox驱动程序【英文标题】:HowdoiwaitforapagetoloadafteraformsubmitsinWebdriver.Iamusingfirefoxdriver【发布时间】:2011-09-0412:22:00【问题描述】:我正在尝试自动化一个测试用例,在该... 查看详情

使用 selenium webdriver 在 Windows 上设置 firefox 二进制文件的路径

】使用seleniumwebdriver在Windows上设置firefox二进制文件的路径【英文标题】:Settingpathtofirefoxbinaryonwindowswithseleniumwebdriver【发布时间】:2014-11-0101:21:50【问题描述】:我正在尝试构建一个实用函数来将漂亮的汤代码输出到浏览器我有... 查看详情

TypeError:WebDriver.__init__() 在 Selenium Python 中使用 firefox_options 作为参数时遇到了意外的关键字参数“firefox_option

】TypeError:WebDriver.__init__()在SeleniumPython中使用firefox_options作为参数时遇到了意外的关键字参数“firefox_options”错误【英文标题】:TypeError:WebDriver.__init__()gotanunexpectedkeywordargument\'firefox_options\'errorusingfirefox_optionsasargument 查看详情