Pass driver ChromeOptions and DesiredCapabilities?

后端 未结 5 1388
盖世英雄少女心
盖世英雄少女心 2020-12-05 05:19

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 su

相关标签:
5条回答
  • 2020-12-05 05:42

    Adding my answer to help users who are still looking for ChromeOptions and Capabilities with Selenium latest version.

    Passing capabilities to ChromeDriver constructor is Deprecated from v3.6.0. Source code Reference

    ChromeDriver(Capabilities capabilities)
    Deprecated. 
    Use ChromeDriver(ChromeOptions) instead.
    

    Instead you should start using something like below :

    ChromeOptions options = new ChromeOptions();
    options.setAcceptInsecureCerts(true);
    options.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.ACCEPT);
    WebDriver driver = new ChromeDriver(options)
    

    You can still have your capabilities defined, but make sure you merge these capabilities with ChromeOptions like below:

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("something", true);
    
    ChromeOptions options = new ChromeOptions();
    options.addArguments("disable-infobars");
    options.merge(capabilities);
    

    You can check article on Selenium ChromeOptions for more detailed usage on ChromeOptions and Capabilities

    0 讨论(0)
  • 2020-12-05 05:42

    may be try this:

    chromeOptions = webdriver.ChromeOptions()
    prefs = {"profile.managed_default_content_settings.images":2}
    chromeOptions.add_experimental_option("prefs",prefs)
    driver = webdriver.Chrome(chrome_options=chromeOptions)
    

    related info can found here: http://nullege.com/codes/search/selenium.webdriver.ChromeOptions.add_experimental_option

    0 讨论(0)
  • 2020-12-05 05:54
    public void setUp() throws Exception
    {
        System.out.println("Launching Google browser");
        System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");   
    
        ChromeOptions options = new ChromeOptions();
        options.addArguments("disable-infobars");
        Map<String, Object> prefs = new HashMap<String, Object>();
        prefs.put("profile.default_content_setting_values.automatic_downloads", 1);
        options.setExperimentalOption("prefs", prefs);
        prefs.put("download.default_directory", "C:\\Downloads");
        driver = new ChromeDriver(options);
        driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
        driver.manage().window().maximize(); 
    }
    
    0 讨论(0)
  • 2020-12-05 06:02

    FYI: This technique does not appear to work with Chrome 41.0.2272.101m.

    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.AddExcludedArgument("ignore-certificate-errors");
    capabilities = DesiredCapabilities.Chrome();
    capabilities.SetCapability(ChromeOptions.Capability, chromeOptions);
    
    new RemoteWebDriver(hubUri, capabilities, TimeSpan.FromSeconds(180))
    

    Generates

    09:39:24.110 WARN - Exception: unknown error: cannot parse capability: chromeOptions
    from unknown error: unrecognized chrome option: Arguments
    (Driver info: chromedriver=2.10.267521,platform=Windows NT 6.3 x86_64) 
    (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 1.52 seconds
    Build info: version: '2.43.0', revision: '597b76b', time: '2014-09-09 20:52:14'
    System info: host: 'T10-E8-GREGPE', ip: '10.123.160.70', os.name: 'Windows 8.1', os.arch: 'x86', os.version: '6.3', java.version: '1.8.0_40'
    Driver info: org.openqa.selenium.chrome.ChromeDriver
    

    This appears to work:

    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.AddArgument("test-type");
    capabilities = (DesiredCapabilities)chromeOptions.ToCapabilities();
    
    new RemoteWebDriver(hubUri, capabilities, TimeSpan.FromSeconds(180));
    
    0 讨论(0)
  • 2020-12-05 06:07

    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);
    
    0 讨论(0)
提交回复
热议问题