'How to set Chrome Options when using WebDriverManager?

I'm using Web driver manager to setup chrome driver. When setting up the driver I want to add some chrome options? How can I do it when using web driver manager?

I checked the WebDriverManager API but couldn't find any clue..



Solution 1:[1]

public void WebDriverManagerTest()
{
    //setup the chromedriver using WebDriverManager
    WebDriverManager.chromedriver().setup();

    //Create Chrome Options
    ChromeOptions option = new ChromeOptions();
    option.addArguments("--test-type");
    option.addArguments("--disable-popup-bloacking");
    DesiredCapabilities chrome = DesiredCapabilities.chrome();
    chrome.setJavascriptEnabled(true);
    option.setCapability(ChromeOptions.CAPABILITY, option);

    //Create driver object for Chrome
    WebDriver driver = new ChromeDriver(option);

    //Navigate to a URL
    driver.get("http://toolsqa.com");

    //quit the browser
    driver.quit();
}

Found the answer.. Check above!

Solution 2:[2]

This is the example code:

public class Test1{
    
    @Test
    public void WebDriverManagerTest()
    {
        //setup the chromedriver using WebDriverManager
        WebDriverManager.chromedriver().setup();
        //Create driver object for Chrome
        WebDriver driver = new ChromeDriver();
        //Navigate to a URL
        driver.get("http://toolsqa.com");
        //quit the browser
        driver.quit();
    }
}

Solution 3:[3]

from https://pypi.org/project/webdriver-manager/, pass it in after .install()

from selenium import webdriver
from webdriver_manager.opera import OperaDriverManager

options = webdriver.ChromeOptions()
options.add_argument('allow-elevated-browser')
options.binary_location = "C:\\Users\\USERNAME\\FOLDERLOCATION\\Opera\\VERSION\\opera.exe"

driver = webdriver.Opera(executable_path=OperaDriverManager().install(), options=options)

Solution 4:[4]

As of WebDriverManager 5.x you can instantiate the webDriver directly via the WebDriverManager builder with additional capabilities this way (in java) :

WebDriver driver;
//...
ChromeOptions options = new ChromeOptions();
    options.addArguments("--headless");
    //...
    //options.addArguments(<another-option>);
    //...
    driver = WebDriverManager.chromedriver().capabilities(options).create();

The capabilities method take a Capabilities as param.
Lucky we are, ChromeOptions implements the Capabilities interface.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 S Chathuranga Jayasinghe
Solution 2 Fahim Bagar
Solution 3 ndb
Solution 4 Philippe Simo