Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
351 views
in Technique[技术] by (71.8m points)

How can Geckodriver/Firefox work without Marionette? (running python selenium 3 against FF 53)

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

enter image description here

  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.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...