3

I updated from selenium 3.141.0 to 4.0.0b4. The code below worked fine before (it opened up google)

import selenium
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)

driver.get("https://google.com.au")

But once I updated, selenium has begun to give me this error message:

Unrecognised option moz:debuggerAddress

I've tried to dig around on the internet for a while and I can't find any resolution. The closest thing I found was another package that had the same issue, but I'm not sure how the fix applies here. I wanted to try and "disable" the moz debuggeraddress option but I don't know how. I never had the option to add it - it seems like something else is mysteriously adding this option for me. How can I make the above code work in 4.0.0.b4 ?

John Hon
  • 183
  • 2
  • 10

2 Answers2

0

I had the same issue after I updated to Selenium 4.0.0. The error ceased to occur after I updated my geckodriver to 0.30.0 and addressed some of the deprecated objects from previous selenium versions, but in the process I may have mistakenly imported the wrong Service and/or Options from Selenium. I think that may be what is going on in your case as well.

I could not replicate the error directly from your code. I used the code below to demonstrate the potential error and the solution.

Service object stack post: DeprecationWarning: executable_path has been deprecated selenium python

Latest geckodriver: https://github.com/mozilla/geckodriver/releases/tag/v0.30.0

I replicated your error by running this in Windows Subsystem for Linux (WSL2) with Ubuntu 20.04 with Selenium 4.0.0 or Selenium 4.0.0b4 (I tested both with the same outcome) with geckodriver v0.28.0.

import pathlib
from selenium import webdriver
from selenium.webdriver.firefox.options import Options

# note the purposeful error in the service import #
from selenium.webdriver.chrome.service import Service

options = Options()

options.headless = True

# I keep my driver in my local folder with my script #
path = f"{pathlib.Path(__file__).parent.absolute()}/geckodriver" 

driver = webdriver.Firefox(service=Service(path), options=options)

print(driver.capabilities['moz:geckodriverVersion'])

driver.get("https://google.com.au")

print(driver.page_source[0:97:1])

driver.quit()

This code returns:

selenium.common.exceptions.InvalidArgumentException: Message: Unrecognised option moz:debuggerAddress

This suggests to me that when running the old gecko driver selenium can't overcome the misused chrome Service. If you switch the purposefully mistaken Service import to firefox as:

from selenium.webdriver.firefox.service import Service

The code will then return:

PermissionError: [Errno 13] Permission denied: '/home/***/geckodriver'

During handling of the above exception, another exception occurred:

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable may have wrong permissions.

Finally, if you update to geckodriver v0.30.0 both of the scripts above will return:

0.30.0 #indicating gecko version #
<html itemscope="" itemtype="http://schema.org/WebPage" lang="en-CA"><head><meta charset="UTF-8"> #a subset of the HTML returned from a page source #

Taken together, I would suggest updating your geckodriver and taking a look at your imports. This is somewhat of an applied solution, if someone has a better understanding of the inner workings of the Service and Options objects they may be able to provide a more detailed answer.

0

I don't have any insight on this, but seems that this parameter is not present anymore, or has another name. This happend to me, then I just digg into the problem and ended up with this.

You can import capabilities, and set it as argument at webdriver creation. So, you can remove such offending parameter. If you don't supply it manually, gets created automatically then miserably fails.

Following your code results in this:

import selenium
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.firefox.options import Options
options = Options()
capabilities = DesiredCapabilities.FIREFOX.copy()
capabilities.pop("moz:debuggerAddress")
options.headless = True
driver = webdriver.Firefox(options=options, capabilities=capabilities)

driver.get("https://google.com.au")

Remember this will work or fail depending on versions and or configs, but at least you have a way to fix it when doesn't want to work.

m3nda
  • 1,986
  • 3
  • 32
  • 45
  • Is good I found myself when the problem backwards and now the problem is that I cannot pop a key that is not present in the dict :-) so I had to comment it out. – m3nda Aug 30 '22 at 11:25