5

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/')
The Dan
  • 1,408
  • 6
  • 16
  • 41
  • Does this answer your question? [How do I pass options to the Selenium Chrome driver using Python?](https://stackoverflow.com/questions/12698843/how-do-i-pass-options-to-the-selenium-chrome-driver-using-python) – M Z Mar 31 '21 at 17:31
  • 1
    Thanks for your answer, but it seems to be unrelated to the question. "selenium.common.exceptions.WebDriverException: Message: Desired Capabilities must be a dictionary " – The Dan Mar 31 '21 at 18:09

2 Answers2

8

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/')
arnaud1050
  • 126
  • 1
  • 5
0

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()
user1090944
  • 445
  • 1
  • 8
  • 16