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..

Upvotes: 12

Views: 13332

Answers (5)

Suraj
Suraj

Reputation: 327

In Pom.xml add Webdriver Manager Dependancy and While Creating a browser instance you can use the below code snipped for running in incognito and without being controlled by automation.

public void setUpChromeBrowser(){

  WebDriverManager.chromedriver().setup();
  ChromeOptions options = new ChromeOptions();
  options.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
  options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);                     
  options.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
                    options.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
                    options.setExperimentalOption("useAutomationExtension", false);
                    options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
                    options.addArguments("--no-sandbox");
                    options.addArguments("--ignore-certificate-errors");
                    options.addArguments("--start-maximised");
                    options.addArguments("--incognito");
                    options.setExperimentalOption("w3c", false);
                    Map<String, Object> prefs = new HashMap<String, Object>();
                    prefs.put("credentials_enable_service", false);
                    prefs.put("profile.password_manager_enabled", false);
                    options.setExperimentalOption("prefs", prefs);
                    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
                    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
                    driver = new ChromeDriver(options);

}

Upvotes: 0

Philippe Simo
Philippe Simo

Reputation: 1459

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 chromeOptions = new ChromeOptions();  

chromeOptions.addArguments("--headless");  

//...  

//chromeOptions.addArguments(<another-option>);  

//...  

driver = WebDriverManager.chromedriver().capabilities(chromeOptions).create();

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

Upvotes: 4

ndb
ndb

Reputation: 129

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)

Upvotes: 0

AshishKumar
AshishKumar

Reputation: 9

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();
    }
}

Upvotes: 0

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!

Upvotes: 1

Related Questions