Geckodriver/Firefox 如何在没有 Marionette 的情况下工作?(针对 FF 53 运行 python selenium 3) [英] How can Geckodriver/Firefox work without Marionette? (running python selenium 3 against FF 53)

查看:19
本文介绍了Geckodriver/Firefox 如何在没有 Marionette 的情况下工作?(针对 FF 53 运行 python selenium 3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只在 selenium 控制的 firefox 弹出窗口中看到一个奇怪的不受信任的证书"错误.很具体.为了解决这个问题,各种谷歌搜索结果建议关闭牵线木偶,如下所示:

from selenium.webdriver.common.desired_capabilities import DesiredCapabilitiesfirefox_capabilities = DesiredCapabilities.FIREFOXfirefox_capabilities['牵线木偶'] = False驱动程序 = webdriver.Firefox()

这有效,但如何?Geckodriver 在 Marionette 关闭的情况下如何工作?

来自

  1. 现在根据 Selenium 3.4.x 规范,我进行了一些修改.将 "marionette" 设为 true 并在初始化驱动程序时添加 executable_path.

<块引用>

需要注意的是,当前的 Selenium-Python 绑定对于 geckodriver 是不稳定的,并且看起来是特定于架构的.您可以找到 github

I'm seeing a bizarre "untrusted cert" error only on selenium-controlled firefox pop-ups. Very specific. To solve this problem, various google results suggested turning off marionette, like so:

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = False
driver = webdriver.Firefox()

And this works, but how?? How is geckodriver working at all with Marionette off?

From this other Stack Overflow answer:

Marionette is an automation driver for Mozilla's Gecko engine.

The answer goes on to explicitly say it should fail:

"In case of using the Firefox 53.x browsers if you forcefully set "marionette" to false through DesiredCapabilities class you will observe a UnreachableBrowserException."

So, how the heck is this working?

解决方案

You have take care of a couple of things as follows:

  1. "untrusted cert" error only on selenium-controlled firefox pop-ups : This is a common issue and we can avoid that through configuring the WebDriver instance through DesiredCapabilities class.
  2. turning off marionette : Turning off marionette is no more a solution while we work with Selenium 3.x and recent Mozilla Firefox Browser releases. By forcefully setting "marionette" to false through DesiredCapabilities class you won't be able to open Mozilla Firefox Browser above version 48.x.
  3. About your code, I don't see any significant errors in your code. You have set "marionette" to false through DesiredCapabilities class but still works and open a Mozilla Firefox Browser session of legacy releases which is also installed on your machine which is below version 48.x
  4. To do a quick test, I simply copied your code and opened the url https://www.whatismybrowser.com/.

Code:

    from selenium import webdriver
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

    firefox_capabilities = DesiredCapabilities.FIREFOX
    firefox_capabilities['marionette'] = False
    driver = webdriver.Firefox()
    driver.get('https://www.whatismybrowser.com/')

Result: Mozilla Firefox version 47 is opened.

  1. Now as per Selenium 3.4.x specifications, I made a couple of modifications. Turned "marionette" to true and added executable_path while initializing the driver.

It is to be noted that the current Selenium-Python binding is unstable with geckodriver and looks to be Architecture specific. You can find the github discussion and merge here. So you may additionally need to pass the absolute path of the firefox binary as firefox_binary argument while initializing the webdriver

Code:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

binary = FirefoxBinary('C:\Program Files\Mozilla Firefox\firefox.exe')
firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
driver = webdriver.Firefox(firefox_binary=binary,executable_path='C:\Utility\BrowserDrivers\geckodriver.exe')
driver.get('https://www.whatismybrowser.com/')

Result: Mozilla Firefox version 53 is opened.

这篇关于Geckodriver/Firefox 如何在没有 Marionette 的情况下工作?(针对 FF 53 运行 python selenium 3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆