7

I am trying to install/configure Selenium to do some UI testing while a team mate is out of the office. I have installed Selenium Webdriver and Eclipse, as well as the Chrome, Firefox and Edge browser drivers. I have some very simple scripts that launch the browser and open up a URL. I am just trying to verify that my install and configuration is good. Firefox and Edge are fine, work as expected. However, I cannot get chrome to work.

Here is my script:

package firstPackage;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class FirstScript {
    public static void main(String[] args) {        
        ChromeOptions options = new ChromeOptions();
        options.addArguments("disable-infobars");
        options.addArguments("--start-maximized");

        WebDriver driver = new ChromeDriver(options);
        driver.get("http://www.google.com");
    }
}

When I run it, Chrome launches. The title of the tab is "data;" and the URL in the address bar is also "data;". However, the browser does not navigate to the URL that I specified. After approx 60 seconds I get the following error in the eclipse window:

Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
  (Driver info: chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 60.15 seconds
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:03.216Z'
System info: host: 'XXXXXXX', ip: 'XXXXXXXXXX', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_171'
Driver info: driver.version: ChromeDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
    at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
    at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
    at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
    at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
    at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
    at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:207)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:157)
    at firstPackage.FirstScript.main(FirstScript.java:14)

A Google search brought me to a few posts that suggested some option settings might do the trick. These are the ones that I tried:

options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("--no-sandbox"); // Bypass OS security model

None of these fixed the problem for me, the behavior stayed the same.

I am running: Windows 10 (OS build 16299) Selenium 3.12.0 ChromeDriver 2.39 Chrome 67.0.3396.79

Anyone have any suggestions as to what I might be doing wrong?

JeffC
  • 22,180
  • 5
  • 32
  • 55
Mike
  • 93
  • 1
  • 1
  • 6
  • Any reason to omit `System.setProperty()` line? – undetected Selenium Jun 08 '18 at 04:48
  • I did not think that it was necessary? The tutorial that I followed gave 2 configuration examples, one that used the System.setProperty to define the path to the webdriver executable, or you could add the path to the PATH ENV variable on the system. It seemed more effective to add the ENV variable, rather then add the line to each script. – Mike Jun 08 '18 at 11:29
  • 1
    Cool, go ahead !!! – undetected Selenium Jun 08 '18 at 11:31
  • I just tried using the System.setProperty, however it did not change the behavior, I still get the same error. – Mike Jun 08 '18 at 11:36

1 Answers1

9

I solved this in Ruby by adding --headless option. Maybe it helps.

Leticia Esperon
  • 2,499
  • 1
  • 18
  • 40
  • You nailed it Leticia! I added the --headless flag, and the test now runs. No more error, and I now get to the page, am able to grab my web elements and am happily testing away in Chrome! – Mike Jun 15 '18 at 18:53