Alex
Alex

Reputation: 44275

How to add selenium chrome options to 'desiredCapabilities'?

For selenium I have a bunch of options for chrome, which I need to pass to the remote webdriver via DesiredCapabilities. On this page there is a java example on how to do this, but how to do it in python? The documentation is very poor.

Here is the code I have so far:

prefs = {
    "profile.default_content_settings.popups":0,
    "download.prompt_for_download": "false",
    "download.default_directory": cwd,
}
chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
chrome_options.add_experimental_option("prefs", prefs) 

capabilities = DesiredCapabilities.CHROME

#code I could not find 
#I need something like
#capabilities.add_options(chrome_options)

driver = webdriver.Remote(
            command_executor='http://aaa.bbb.ccc:4444/wd/hub',
            desired_capabilities=capabilities)

Any idea ho to do this? Or where to find proper documentation?

Upvotes: 7

Views: 22081

Answers (1)

Florent B.
Florent B.

Reputation: 42518

Use options.to_capabilities() to get the capabilities from the options:

options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("--disable-gpu")

capabilities = options.to_capabilities()

driver = webdriver.Remote( \
  command_executor='http://127.0.0.1:4444/wd/hub', \
  desired_capabilities=capabilities)

Upvotes: 16

Related Questions