0

i have this code and one problem(description under code) in its execution

   try {
        ChromeOptions options = new ChromeOptions();
        options.setBinary("/usr/bin/chromium-browser");
        options.addArguments("--start-maximized");
        options.addArguments("headless");
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();

        capabilities.setBrowserName("chrome");
        capabilities.setPlatform(Platform.LINUX);

        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        WebDriver driver = null;

        // here throws exception
        driver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), capabilities);
    }catch (Exception ex){
        int point = 0;
    }

I use:

  1. Ubuntu 14.04.5 LTS
  2. selenium-server-standalone-3.7.1
  3. dependency org.seleniumhq.selenium:selenium-java:3.7.1
  4. ChromeDriver(for Linux 64)
  5. Chromium(instead of just chrome)
  6. xvfb

and when i create RemoteWebDriver i get this error: Exception: unknown error: Chrome failed to start: crashed

command to start selenium-server

DISPLAY=:1 xvfb-run java  -Dwebdriver.chrome.driver="/home/builds/chromedriver" -jar /home/builds/selenium-server-standalone-3.7.1.jar

which of the parts of this scheme can be the cause of the described error?

1 Answers1

0

First all the argument you have entered is wrong for headless.

It's --headless not headless

Use below code

options.addArguments("--headless");

Another thing you have to pass System.setProperty like below:

 System.setProperty("webdriver.chrome.driver","E:\\Selenium\\src\\libs\\chromedriver.exe");

The code working fine from my side is:

         try {
             System.setProperty("webdriver.chrome.driver","E:\\Selenium\\Workplace\\Selenium\\src\\libs\\chromedriver.exe");
                ChromeOptions options = new ChromeOptions();
            //    options.setBinary("/usr/bin/chromium-browser");
                options.addArguments("--start-maximized");
                options.addArguments("--headless");
                DesiredCapabilities capabilities = DesiredCapabilities.chrome();

                capabilities.setBrowserName("chrome");
                capabilities.setPlatform(Platform.WINDOWS);

                capabilities.setCapability(ChromeOptions.CAPABILITY, options);
                WebDriver driver =  new ChromeDriver(capabilities);
                driver.get("http://google.com");


            }catch (Exception ex){
                int point = 0;
            }

    }
Shubham Jain
  • 16,610
  • 15
  • 78
  • 125