【问题标题】:WebDriverError@chrome instead of WebDriverError@firefox while using Firefox browser with selenium使用带有 selenium 的 Firefox 浏览器时使用 WebDriverError@chrome 而不是 WebDriverError@firefox
【发布时间】:2022-07-22 17:26:16
【问题描述】:

我正在尝试使用selenium 编写几个测试,但我看到了以下奇怪的行为。 当我像这样运行测试时:

from selenium.webdriver import Firefox, FirefoxOptions
from selenium.webdriver.firefox.service import Service

options = FirefoxOptions()
service = Service()

brow = Firefox(service=service, options=options)
brow.execute("get", {'url': 'https://python.org'})

我得到了预期的结果,python.org 网站在 Firefox 浏览器中打开。

但如果我在 URL 中出错,我会收到以下错误:

from selenium.webdriver import Firefox, FirefoxOptions
from selenium.webdriver.firefox.service import Service

options = FirefoxOptions()
service = Service()

brow = Firefox(service=service, options=options)
brow.execute("get", {'url': 'qwerty'})
selenium.common.exceptions.InvalidArgumentException: Message: Malformed URL: URL constructor: qwerty is not a valid URL.
Stacktrace:
WebDriverError@chrome://remote/content/shared/webdriver/Errors.jsm:186:5
InvalidArgumentError@chrome://remote/content/shared/webdriver/Errors.jsm:315:5
GeckoDriver.prototype.navigateTo@chrome://remote/content/marionette/driver.js:804:11

我只是想了解为什么我在这里看到WebDriverError@chrome,而不是WebDriverError@firefox 或类似的东西。

这是一个错误,还是我做错了什么?

【问题讨论】:

  • 大概就是selenium代码内部是怎么写的

标签: python python-3.x selenium selenium-webdriver firefox


【解决方案1】:

这些错误信息...

WebDriverError@chrome://remote/content/shared/webdriver/Errors.jsm:186:5
InvalidArgumentError@chrome://remote/content/shared/webdriver/Errors.jsm:315:5
GeckoDriver.prototype.navigateTo@chrome://remote/content/marionette/driver.js:804:11

包含短语 @chrome 可能会在使用 GeckoDriver 组合时给人留下奇怪行为的印象。

但是,根据@AutomatedTester 在GitHub 讨论Selenium 3.4.0-GeckoDriver 0.17.0 : GeckoDriver producing logs through Chromium/Chrome modules #787 中的评论:

这些错误无需担心。 Mozilla 出于不同的原因使用不同的开源项目来构建 Firefox。从整体上看,它显示 Chrome 错误没有任何意义。

所以你可以放心地忽略它们。

【讨论】:

    猜你喜欢
    • 2012-05-25
    • 2015-06-08
    • 2019-11-20
    • 2016-01-06
    • 1970-01-01
    • 2016-10-30
    • 2017-08-27
    • 1970-01-01
    • 2017-08-01
    相关资源
    最近更新 更多