How to set Chrome Options when using WebDriverManager?
Asked Answered
Y

5

12

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

Yasmin answered 17/8, 2019 at 6:26 Comment(1)
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)Copter
Y
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!

Yasmin answered 17/8, 2019 at 7:27 Comment(3)
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}Selmore
DesiredCapabilities chrome = DesiredCapabilities.chrome(); // Error * Multiple markers at this line - DesiredCapabilities cannot be resolved - * DesiredCapabilities cannot be resolved to a type */Selmore
WebDriver driver = new ChromeDriver(option); // Error:Type mismatch: cannot convert from ChromeDriver to WebDriver}Selmore
C
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 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.

Caiaphas answered 5/5, 2022 at 8:33 Comment(0)
Y
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!

Yasmin answered 17/8, 2019 at 7:27 Comment(3)
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}Selmore
DesiredCapabilities chrome = DesiredCapabilities.chrome(); // Error * Multiple markers at this line - DesiredCapabilities cannot be resolved - * DesiredCapabilities cannot be resolved to a type */Selmore
WebDriver driver = new ChromeDriver(option); // Error:Type mismatch: cannot convert from ChromeDriver to WebDriver}Selmore
C
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();
    }
}
Condemnation answered 4/8, 2020 at 11:51 Comment(0)
I
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)
Iodometry answered 24/12, 2021 at 11:36 Comment(0)
L
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);

}

Louth answered 22/5, 2023 at 9:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.