Headless Chrome run with selenium

前端 未结 2 1127
长发绾君心
长发绾君心 2021-01-07 15:22
        System.setProperty(\"webdriver.chrome.driver\", \"/usr/bin/google-chrome\");

        final ChromeOptions chromeOptions = new ChromeOptions();
        //chro         


        
相关标签:
2条回答
  • 2021-01-07 15:44
    options.addArguments("headless");
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    

    This worked for me. Chromedriver Version:2.37

    0 讨论(0)
  • 2021-01-07 15:46

    What are the versions of your Chrome browser, chromedriver and Selenium? I tried with:

    1. Chrome Version 62.0.3202.75 (Official Build) (64-bit)
    2. chromedriver 2.33
    3. Selenium 3.6.0

    The following code:

        System.setProperty("webdriver.chrome.driver", "/pathTo/chromedriver);
    
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("--headless");
    
        ChromeDriver driver = new ChromeDriver(chromeOptions);
        driver.get("https://the-internet.herokuapp.com/login");
        System.out.println(driver.getTitle());
    

    Note: In current versions of Selenium and ChromeDriver replace:

        chromeOptions.addArguments("--headless");
    

    with

        chromeOptions.setHeadless(true);
    

    Ref: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/chrome/ChromeOptions.html#setHeadless-boolean- Also you must set Window size otherwise it renders in mobile mode and you may not get certain elements in the page.

        chromeOptions.addArguments("--window-size=1200x600");
    

    Tested on chromedriver 2.42.591071 with Selenium 3.14.0

    The output:

    The Internet
    

    Take a look to Getting Started with Headless Chrome about the browser support versions.

    0 讨论(0)
提交回复
热议问题