10

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

  • Welcome to StackOverflow. For questions like this, it's very useful to show what you have tried and hasn't worked. Could you share what you have tried so far? (share your code) – kajahno Aug 17 '19 at 07:26

5 Answers5

3

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.

Philippe Simo
  • 1,353
  • 1
  • 15
  • 28
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!

  • using the above code but it is not working public class TestLogin{ @BeforeTest public void Setup() { WebDriverManager.chromedriver().setup(); DesiredCapabilities chrome = DesiredCapabilities.chrome(); // Error * Multiple markers at this line - DesiredCapabilities cannot be resolved - * DesiredCapabilities cannot be resolved to a type */ chrome.setJavascriptEnabled(true); chrome.setCapability(ChromeOptions.CAPABILITY, option); WebDriver driver = new ChromeDriver(option); // Error:Type mismatch: cannot convert from ChromeDriver to WebDriver} – Anjani Kumar Aug 26 '20 at 17:03
  • DesiredCapabilities chrome = DesiredCapabilities.chrome(); // Error * Multiple markers at this line - DesiredCapabilities cannot be resolved - * DesiredCapabilities cannot be resolved to a type */ – Anjani Kumar Aug 26 '20 at 17:04
  • WebDriver driver = new ChromeDriver(option); // Error:Type mismatch: cannot convert from ChromeDriver to WebDriver} – Anjani Kumar Aug 26 '20 at 17:04
0

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();
    }
}
Fahim Bagar
  • 798
  • 7
  • 17
0

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)
ndb
  • 99
  • 1
  • 5
0

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

}

Suraj
  • 317
  • 4
  • 7