1
        System.setProperty("webdriver.chrome.driver", "/usr/bin/google-chrome");

        final ChromeOptions chromeOptions = new ChromeOptions();
        //chromeOptions.addArguments("headless");
        chromeOptions.addArguments("window-size=1200x600");

        final DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
        desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);


        final URL url = new URL("https://the-internet.herokuapp.com/login");
        final WebDriver driver = new RemoteWebDriver(url, desiredCapabilities);

fails as:

Exception in thread "main" org.openqa.selenium.WebDriverException: Unable to parse remote response:

Not Found

Any idea why?

Followed: How to connect to Chromium Headless using Selenium

ses
  • 13,174
  • 31
  • 123
  • 226

2 Answers2

5

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.

Davide Patti
  • 3,391
  • 2
  • 18
  • 20
  • Version 60.0.3112.90 (Official Build) (64-bit), ubuntu, Selenium 3.6.0, chromedriver 3.6.0 - too – ses Nov 02 '17 at 11:34
  • @ses the current last version of chromedriver is the 2.33 :) – Davide Patti Nov 02 '17 at 11:36
  • ok. will check. for me it comes from : import org.openqa.selenium.chrome.ChromeDriver- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver.. ok: https://chromedriver.storage.googleapis.com/index.html – ses Nov 02 '17 at 12:16
  • I found the correct format to be `addArguments("window-size=1200,600")` – not2savvy Jan 26 '23 at 16:19
1
options.addArguments("headless");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);

This worked for me. Chromedriver Version:2.37

Anj Raju
  • 606
  • 7
  • 7