Getting TypeError: WebDriver.__init__() got an unexpected keyword argument ‘desired_capabilities’ when using Appium with Selenium 4.10
Asked Answered
L

3

13

Error: HOOK-ERROR in before_scenario: TypeError: WebDriver.__init__() got an unexpected keyword argument 'desired_capabilities'

Hello, we currently cannot run our script together with the latest Selenium 4.10. Is this Appium error or Python error?

Here is the capabilities that we used. We're currently trying to get the capabilities for platformName by targetOS = self.driver.capabilities['platformName'] but we're hit with this error

capabilities = {
    "platformName": "Android",
    "appium:platformVersion": "11.0",
    "appium:deviceName": "emulator-5554",
    "appium:app": "/Users/faithberroya/Downloads/test.apk",
    "appium:automationName": "UiAutomator2",
    "appium:appPackage": "com.test.school.assignment.rc",
    "appium:appActivity": "com.test.school.assignment.ui.SplashActivity"
}

# launch app
context.driver = webdriver.Remote("http://0.0.0.0:4723/wd/hub", capabilities)
# add wait time
context.driver.implicitly_wait(20)
# app
context.app = Application(context.driver)

Current pip list

Appium-Python-Client     2.10.1
behave                   1.2.6
certifi                  2023.5.7
pip                      23.1.1
requests                 2.31.0
selenium                 4.9.0
Lattice answered 8/6, 2023 at 8:56 Comment(0)
L
21

This is due to changes in selenium 4.10.0: https://github.com/SeleniumHQ/selenium/commit/9f5801c82fb3be3d5850707c46c3f8176e3ccd8e

Changes_in_selenium_4_10_0

Note that desired_capabilities has been removed from the __init__, but there is now another way of passing it in. See https://www.selenium.dev/documentation/webdriver/getting_started/upgrade_to_selenium_4/#capabilities for the documentation on how to pass in desired capabilities when using selenium 4.10.0 (or newer).

Here's a code snippet on using capabilities in the new version:

from selenium.webdriver.firefox.options import Options as FirefoxOptions
options = FirefoxOptions()
cloud_options = {}
cloud_options['build'] = "build_1"
cloud_options['name'] = "test_abc"
options.set_capability('cloud:options', cloud_options)
driver = webdriver.Remote("http://0.0.0.0:4723/wd/hub", options=options)
Lengel answered 8/6, 2023 at 14:24 Comment(2)
I downgraded selenium==4.9.1 and it worked for my caseHernandes
what is the solution for desired_capabilities? this is for set_capabilities. what i want to desired_capabilities=webdriver.DesiredCapabilities.CHROMEMoulmein
O
3

I face similar issue. By default Appium python client uses latest selenium release(4.10.0). So i downgraded the version to 4.9.0 with Appium-python-client as 2.9.0 and it worked fine.

Octave answered 8/6, 2023 at 15:3 Comment(4)
Same solution for now we have the latest Appium but downgraded the selenium to 4.9.0Lattice
Downgrading is not a solution, it is a feature change. you will eventually get into this situation in the future. what we need are examples how to rewrite our code so it work with the new version.Unclog
@Unclog I think it is useful to have answers that show how to patch the client code, as well as answers that indicate which version to downgrade to in order to keep old code working. This answer contributes a useful piece of information.Mcintire
what is the solution for robotframework if I need to run the seleium 4.10? I cannot downgradeDeese
A
1

Appium-Python-Client,The version is too high, try version Appium-Python-Client==1.2.0

Acanthopterygian answered 8/6, 2023 at 10:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.