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?
Creating an instance of ChromeOptions class: See below code: ChromeOptions options = new ChromeOptions(); options. addArguments("disable-infobars"); ChromeDriver driver = new ChromeDriver(options);
Using the ChromeOptions class You can create an instance of ChromeOptions, which has convenient methods for setting ChromeDriver-specific capabilities. You can then pass the ChromeOptions object into the ChromeDriver constructor: ChromeOptions options = new ChromeOptions();
Export your code as jar without the chromedriver. Create a folder ChromeDriver. Place your chromedriver.exe in this folder. Place ChromeDriver folder along with your jar.
ChromeOptions class has introduced in the latest/updated version of Selenium. It is helpful to make changes in the Chrome browser whereas, DesiredCapabilities is an old concept (its usage in Java is deprecated.) to configure or make changes in the browser. Save this answer.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With