selenium-wire
selenium-wire copied to clipboard
Remote with service works in selenium and not in seleniumwire
If import from selenium import webdriver
=> works
if import from seleniumwire import webdriver
=> not works
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
import selenium.webdriver.chrome.service as service
from selenium import webdriver
if __name__ == '__main__':
webdriver_str = ChromeDriverManager().install()
option = webdriver.ChromeOptions()
#driver = WebDriver(ChromeDriverManager().install())
service_chrome = service.Service(webdriver_str)
service_chrome.start()
driver = webdriver.Remote(service_chrome.service_url,
options=option)
driver.get('https://www.selenium.dev/')
element = driver.find_element(by=By.CSS_SELECTOR, value='input[type=search]')
element.click()
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: No matching capabilities found
Thanks for raising this. Which versions of Selenium and Selenium Wire are you using?
@wkeeling seleniumwire: '4.5.4' (Problem requests https://github.com/wkeeling/selenium-wire/issues/452) selenium: '4.1.0'
@wkeeling in seleniumwire\webdriver.py in Remote Class, I think this solves the problem:
if seleniumwire_options.get('auto_config', True):
capabilities = {}
try:
if kwargs.get('options'):
capabilities = kwargs.get('options').to_capabilities()
else:
capabilities = kwargs.get('desired_capabilities')
except:
pass
if capabilities is None:
capabilities = DesiredCapabilities.FIREFOX.copy()
capabilities = self._configure(capabilities, seleniumwire_options)
kwargs['desired_capabilities'] = capabilities
super().__init__(*args, **kwargs)
@FranciscoPalomares this error is happening because there is a mismatch in the type of desired capabilities that Selenium Wire is sending. You're running Chrome but Selenium Wire is sending the desired capabilities for Firefox.
I'll look at figuring out how to fix this, but in the meantime you can work around the problem by supplying the correct desired capabilities in your code:
from selenium.webdriver import DesiredCapabilities
driver = webdriver.Remote(
service_chrome.service_url,
options=option,
desired_capabilities=DesiredCapabilities.CHROME.copy() # Pass an empty Chrome desired capabilities
)