Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass driver ChromeOptions and DesiredCapabilities?

The new Google chrome update causes this message in the browser "You are using an unsupported command-line flag: --ignore-certificate-errors. Stability and security will suffer."

From what I read on selenium bug reports, the temporary solution is to start webdriver with

options.AddArgument("test-type")

I was already passing DesiredCapabilities when creating the driver. How can I pass both ChromeOptions and DesiredCapabilities to the driver?

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--incognito"));

ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");

WebDriver driver = new ChromeDriver(capabilities);
like image 316
Arya Avatar asked May 23 '14 16:05

Arya


People also ask

What is difference between DesiredCapabilities and ChromeOptions?

Summary: Selenium Chrome Options class is used to manipulate various properties of Chrome driver. Desired Chrome Capabilities class provides a set of key-value pairs to modify individual properties of web driver such as browser name, browser platform, etc.

What is ChromeOptions?

ChromeOptions is a new concept added in Selenium WebDriver starting from Selenium version 3.6. 0 which is used for customizing the ChromeDriver session. By default when selenium opens up any browser (Chrome browser or Firefox browser), it opens up without any extension or history or cookies, etc.

What is DesiredCapabilities?

DesiredCapabilities are a set of key-value pairs encoded as a JSON object. It helps QAs define basic test requirements such as operating systems, browser combinations, browser versions, etc. within Selenium test scripts.

How do I pass ChromeOptions in Selenium Python?

For the ChromeOptions, we have to create an object for that class. Then we shall take the help of the add_argument method and pass the option we want to send to the browser as a parameter to the method. Finally, this information must be given to the web driver.


1 Answers

I was fighting the same problem, and I finally cracked it. Basically, you can add ChromeOptions to DesiredCapabilities then create the driver with the DesiredCapabilities. Once I tried it, it got rid of the banner. Anyway, here is the code:

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
capabilities.setCapability("chrome.binary", "<Path to binary>");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
webDriver = new ChromeDriver(capabilities);
like image 129
JoshM Avatar answered Oct 08 '22 14:10

JoshM