wkeeling / selenium-wire

Extends Selenium's Python bindings to give you the ability to inspect requests made by the browser.
MIT License
1.86k stars 240 forks source link

TypeError: WebDriver.__init__() got an unexpected keyword argument 'desired_capabilities' #697

Open pedrofnts opened 11 months ago

pedrofnts commented 11 months ago

Hello, I'm trying to use webdriver.Remote with selenium-wire to create an instance of browserless, but I keep getting this error

_TypeError: WebDriver.init() got an unexpected keyword argument 'desiredcapabilities'

Here's my code:

def create_chrome_driver():
    options = webdriver.ChromeOptions()
    options.add_argument("--disable-dev-shm-usage")
    options.add_argument("--no-sandbox")
    options.add_argument("--start-maximized")
    options.add_argument("--window-size=1920x1080")
    options.set_capability('browserless:stealth', True)
    proxies = chrome_proxy(proxy_username, proxy_password, proxy_endpoint)

    driver = webdriver.Remote(
        command_executor='https://**my api**@chrome.browserless.io/webdriver',
        options=options, seleniumwire_options=proxies)

    return driver

I'm not passing desidered_capabilities. Why this is happening?

jdholtz commented 11 months ago

The linked PR will not fix this issue in its current state. More work would need to be done to make a fix for this possible (if desired by wkeeling).

hrf2 commented 9 months ago

Bump.

I'm running into the same issue, a fix would be greatly appreciated.

(Just to clarify: I'm also trying to use webdriver.Remote, and getting the same error message regarding desidered_capabilities even though I haven't passed it as an argument.)

surfingdoggo commented 9 months ago

Another bump

Error:

TypeError: WebDriver.__init__() got an unexpected keyword argument 'desired_capabilities'

Code (no clue if it would work anyway, working on it):

from seleniumwire import webdriver
options = {
    'proxy': {
        'http': the_proxy_addr, 
        'https': the_proxy_addr,
        # 'no_proxy': 'localhost,127.0.0.1', # excludes
        'custom_authorization': f'{username} {password}' 
    }
}
driver = webdriver.Remote(
    command_executor= "http://172.17.0.2:4444/wd/hub", 
    seleniumwire_options=options
)

@pedrofnts the issue is happening because desired_capabilities was deprecated as of 4.10.0 and I'm assuming seleniumwire uses it under the hood in some way.

You can downgrade which I might try but I'm not a huge fan of that solution.

surfingdoggo commented 9 months ago

Update: I tried it on 4.9.1 and it still didn't work :(

If I figure anything else out I'll share with the class

pedrofnts commented 9 months ago

@surfingdoggo test this:

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"})

https://github.com/wkeeling/selenium-wire/issues/687#issuecomment-1732311567

alexppg commented 8 months ago

@surfingdoggo test this:

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"})

https://github.com/wkeeling/selenium-wire/issues/687#issuecomment-1732311567

This does not work, I'm afraid. The issue persists.