selenium-wire
selenium-wire copied to clipboard
Capabilities was removed in Selenium 4.10.0
Hello! I have a problem after updating Selenium to v 4.10.0. I use the Remote Chrome driver in one class in my test set.
from seleniumwire import webdriver as wire_driver
options = Options()
capabilities = options.to_capabilities()
driver = wire_driver.Remote(
command_executor="http://localhost:3000/webdriver",
options=options,
desired_capabilities=capabilities
After updating selenium to v 4.10.0, this error began to appear:
failed on setup with "TypeError: WebDriver.__init__() got an unexpected keyword argument 'desired_capabilities'"
cls = <class 'test_objects1.auc_1_user_registers_in_the_system.test_registration_user.UserRegisteredTests'>
@classmethod
def setUpClass(cls) -> None:
try:
if cls.__name__ == "UserRegisteredTests":
> BaseTestCase._driver = WebDriverFactory.get_driver(
is_traffic_intercepted=True
)
test_objects1/base_test_case.py:106:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
webdriver_factory.py:80: in get_driver
driver = WebDriverFactory.get_remote_driver(is_traffic_intercepted)
webdriver_factory.py:186: in get_remote_driver
driver = wire_driver.Remote(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <[AttributeError("'Remote' object has no attribute 'session_id'") raised in repr()] Remote object at 0x7f2e03032d90>
seleniumwire_options = {}, args = ()
kwargs = {'command_executor': 'http://localhost:3000/webdriver', 'desired_capabilities': {'acceptInsecureCerts': True, 'browser...}, 'pageLoadStrategy': 'normal', ...}, 'options': <selenium.webdriver.chrome.options.Options object at 0x7f2e033c4d90>}
config = {'acceptInsecureCerts': True, 'proxy': {'httpProxy': '127.0.0.1:42423', 'proxyType': 'manual', 'sslProxy': '127.0.0.1:42423'}}
capabilities = {'acceptInsecureCerts': True, 'browserName': 'chrome', 'goog:chromeOptions': {'args': ['--window-size=1280, 720', '--h...ndbox', '--disable-smooth-scrolling', '--disable-dev-shm-usage'], 'extensions': []}, 'pageLoadStrategy': 'normal', ...}
def __init__(self, *args, seleniumwire_options=None, **kwargs):
"""Initialise a new Firefox WebDriver instance.
Args:
seleniumwire_options: The seleniumwire options dictionary.
"""
if seleniumwire_options is None:
seleniumwire_options = {}
config = self._setup_backend(seleniumwire_options)
if seleniumwire_options.get('auto_config', True):
capabilities = kwargs.get('desired_capabilities')
if capabilities is None:
capabilities = DesiredCapabilities.FIREFOX.copy()
else:
capabilities = capabilities.copy()
capabilities.update(config)
kwargs['desired_capabilities'] = capabilities
> super().__init__(*args, **kwargs)
E TypeError: WebDriver.__init__() got an unexpected keyword argument 'desired_capabilities'
/usr/local/lib/python3.11/site-packages/seleniumwire/webdriver.py:308: TypeError
If I don't pass capability the Remote Firefox driver is called, but I expected Remote Chrome driver
You managed to solve that?
For old selenium (< 4.10): dc = DesiredCapabilities.CHROME.copy() dc["goog:loggingPrefs"] = {"browser":"INFO"}
For "new" selenium (>=4.10), you need to place it using options.set_capability: options = webdriver.ChromeOptions() options.set_capability("goog:loggingPrefs", {browser: "INFO"})
I belive this is a duplicated https://github.com/wkeeling/selenium-wire/issues/697.
The problem seems to be here.
if seleniumwire_options.get('auto_config', True):
capabilities = kwargs.get('desired_capabilities')
if capabilities is None:
capabilities = DesiredCapabilities.FIREFOX.copy()
else:
capabilities = capabilities.copy()
capabilities.update(config)
kwargs['desired_capabilities'] = capabilities
I don't know why this is used, but it's the cause of the problem. When commenting it, the error is not reproduced, since the desired_capabilities
is not passed to selenium's webdriver's class.
It would seem that this commit is the one that removed the desired_capabilities
options https://github.com/SeleniumHQ/selenium/commit/9f5801c82fb3be3d5850707c46c3f8176e3ccd8e.
EDIT: Aclaration, this doesn't solve the problem, it just doesn't reproduce the error. For example, I'm able to add a proxxy when using local chromedriver but not a remote selenium server.
I belive this is a duplicated #697.
I created this topic first
Sure, I didn't meant it for you to close it, just to create the link relating the two of them. I think this has better documentation, I'd leave this open.