ChromeDriver desired_capabilities has been deprecated, please pass in an Options object with options kwarg

21.4k Views Asked by At

I am getting this deprecation warning when I start my Selenium webdriver.Remote in python, my selenium version is selenium==4.0.0b2.post1

desired_capabilities has been deprecated, please pass in an Options object with options kwarg

What is that Option object supposed to be? How do I declare it?

This is my code:

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium import webdriver
import time

driver = webdriver.Remote(
    command_executor='http://localhost:4444/wd/hub',
    desired_capabilities=DesiredCapabilities.CHROME
)

driver.get('http://www.google.com/')
2

There are 2 best solutions below

1
On

You can use Options instead of DesiredCapabilities in the following way:

from selenium import webdriver
import time

driver = webdriver.Remote(
    command_executor='http://localhost:4444/wd/hub',
    options=webdriver.ChromeOptions()
)

driver.get('http://www.google.com/')
0
On

For selenium running on MacOS you can use options like this:

from selenium import webdriver

driver = webdriver.Remote(
    command_executor='http://localhost:4444',
    options=webdriver.FirefoxOptions()
)

driver.get('https://google.com')

driver.quit()

For selenium running on Windows you can use options like this:

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

options = Options()
options.binary_location = r"C:\\Program Files\\Mozilla Firefox\\firefox.exe"

driver = webdriver.Remote(
    command_executor='http://127.0.0.1:4444',
    options=options
)

driver.get('http://google.com')

driver.quit()

If you are using Appium automation, this worked for me:

from appium import webdriver

APPIUM = 'http://localhost:4723'
CAPS = {
    'platformName': 'iOS',
    'platformVersion': '16.2',
    'deviceName': 'iPhone 14',
    'automationName': 'XCUITest',
    'browserName': 'Safari'
}

driver = webdriver.Remote(
    command_executor=APPIUM,
    desired_capabilities=CAPS
)

try:
    driver.get('https://google.com')
finally:
    driver.quit()