简体   繁体   中英

Selenium 3.8.1, ChromeDriver 2.34 - org.openqa.selenium.WebDriverException: chrome not reachable

While executing Selenium-Jvm, Chrome does not start intermittently and throws "chrome not reachable" error. Same scripts work fine for IE

Below is the code. I am using Chrome browser Version 63.0.3239.84 (Official Build) (64-bit).

package sampleSelenium;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class RunScript {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        WebDriver driver;
        System.setProperty("webdriver.chrome.driver", "D:/browser_drivers/chromedriver.exe");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("disable-infobars");

        for (int i=0; i<10;i++)
        {
            try {

                driver = new ChromeDriver(options);

                driver.manage().deleteAllCookies();
                driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
                driver.navigate().to("https://XXXX.XXXX.com/");
                Dimension dimension = new Dimension(1920, 1080);
                driver.manage().window().setSize(dimension);

                String currentWindow = driver.getWindowHandle();
                driver.switchTo().window(currentWindow);

                WebElement elm = driver.findElement(By.cssSelector("#username"));
                System.out.println(elm.isDisplayed());
                elm = driver.findElement(By.cssSelector("#password"));
                System.out.println(elm.isDisplayed());
                elm = driver.findElement(By.cssSelector("#Login"));
                System.out.println(elm.isDisplayed());

                driver.findElement(By.cssSelector("#username")).sendKeys("XXX");
                driver.findElement(By.cssSelector("#password")).sendKeys("XXX");
                driver.findElement(By.cssSelector("#Login")).click();

                WebDriverWait wait = new WebDriverWait(driver, 2);
                System.out.println("waiting");
                try {
                    WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("mb12")));

                }
                catch(Exception e) {
                    System.out.println(e);
                };

                driver.close();
                driver.quit();

            }
            catch(Exception e) {
                System.out.println(e);
            };


        }

    }

}


*********Error***********

    Starting ChromeDriver 2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1) on port 5871
    Only local connections are allowed.
    Dec 21, 2017 9:14:09 AM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Detected dialect: OSS
    true
    true
    true
    waiting
    org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.className: mb12 (tried for 2 second(s) with 500 MILLISECONDS interval)
    Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:14.666Z'
    System info: host: 'XXXXXXX', ip: 'XXXXXXX', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_151'
    Driver info: org.openqa.selenium.chrome.ChromeDriver
    Capabilities {acceptSslCerts: true, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.34.522940 (1a76f96f66e3ca..., userDataDir: C:\Users\XXXX\AppData\Lo...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 63.0.3239.108, webStorageEnabled: true}
    Session ID: c7c48eb76525894292da06d1e5ed8f07
    Starting ChromeDriver 2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1) on port 31553
    Only local connections are allowed.
    org.openqa.selenium.WebDriverException: chrome not reachable
      (Driver info: chromedriver=2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 61.61 seconds
    Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:14.666Z'
    System info: host: 'XXXXXX', ip: 'XXXXXXX', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_151'
    Driver info: driver.version: ChromeDriver

We have referred all the old posts and tried providing absolute path for chrome binary as well as chromedriver but no luck. Also tried setting no_proxy for localhost and 127.0.0.1

More additional logs is provided below.

The log with id 100 below is not working and missing some operations in the debug log

11:41:47,744 DEBUG http-outgoing-100 << "HTTP/1.1 200 OK[\r][\n]"
11:41:47,744 DEBUG http-outgoing-100 << "Content-Length:230[\r][\n]"
11:41:47,744 DEBUG http-outgoing-100 << "Content-Type:application/json; charset=utf-8[\r][\n]"
11:41:47,744 DEBUG http-outgoing-100 << "Connection:close[\r][\n]"
11:41:47,744 DEBUG http-outgoing-100 << "[\r][\n]"
11:41:47,744 DEBUG http-outgoing-100 << "{"sessionId":"fdebdff9e23b0d3715fb3b903cdf082b","status":100,"value":{"message":"chrome not reachable\n  (Driver info: chromedriver=2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1),platform=Windows NT 6.1.7601 SP1 x86_64)"}}"
11:41:47,744 DEBUG http-outgoing-100 << HTTP/1.1 200 OK
11:41:47,744 DEBUG http-outgoing-100 << Content-Length:230
11:41:47,744 DEBUG http-outgoing-100 << Content-Type:application/json; charset=utf-8
11:41:47,744 DEBUG http-outgoing-100 << Connection:close
11:41:47,744 DEBUG http-outgoing-100: Close connection
11:41:47,744 DEBUG Connection discarded
11:41:47,744 DEBUG Connection released: [id: 100][route: {}->http://localhost:48950][total kept alive: 0; route allocated: 0 of 2000; total allocated: 2 of 2000]

while id 229 is opening the connection correctly.

11:41:26,756 DEBUG CookieSpec selected: default
11:41:26,756 DEBUG Auth cache not set in the context
11:41:26,756 DEBUG Connection request: [route: {}->http://localhost:39283][total kept alive: 0; route allocated: 0 of 2000; total allocated: 3 of 2000]
11:41:26,756 DEBUG Connection leased: [id: 229][route: {}->http://localhost:39283][total kept alive: 0; route allocated: 1 of 2000; total allocated: 4 of 2000]
11:41:26,756 DEBUG Opening connection {}->http://localhost:39283
11:41:26,756 DEBUG Connecting to localhost/127.0.0.1:39283
11:41:26,756 DEBUG Connection established 127.0.0.1:50151<->127.0.0.1:39283
11:41:26,756 DEBUG http-outgoing-229: set socket timeout to 10800000
11:41:26,756 DEBUG Executing request DELETE /session/bf4589ba8b779464252afb0a20e55e0c HTTP/1.1
11:41:26,756 DEBUG Target auth state: UNCHALLENGED
11:41:26,756 DEBUG Proxy auth state: UNCHALLENGED
11:41:26,756 DEBUG http-outgoing-229 >> DELETE /session/bf4589ba8b779464252afb0a20e55e0c HTTP/1.1
11:41:26,756 DEBUG http-outgoing-229 >> Host: localhost:39283
11:41:26,756 DEBUG http-outgoing-229 >> Connection: Keep-Alive
11:41:26,756 DEBUG http-outgoing-229 >> User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_131)
11:41:26,756 DEBUG http-outgoing-229 >> Accept-Encoding: gzip,deflate
11:41:26,756 DEBUG http-outgoing-229 >> "DELETE /session/bf4589ba8b779464252afb0a20e55e0c HTTP/1.1[\r][\n]"
11:41:26,756 DEBUG http-outgoing-229 >> "Host: localhost:39283[\r][\n]"
11:41:26,756 DEBUG http-outgoing-229 >> "Connection: Keep-Alive[\r][\n]"
11:41:26,756 DEBUG http-outgoing-229 >> "User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_131)[\r][\n]"
11:41:26,756 DEBUG http-outgoing-229 >> "Accept-Encoding: gzip,deflate[\r][\n]"
11:41:26,756 DEBUG http-outgoing-229 >> "[\r][\n]"
11:41:26,803 DEBUG http-outgoing-229 << "HTTP/1.1 200 OK[\r][\n]"
11:41:26,803 DEBUG http-outgoing-229 << "Content-Length:40[\r][\n]"
11:41:26,803 DEBUG http-outgoing-229 << "Content-Type:application/json; charset=utf-8[\r][\n]"
11:41:26,803 DEBUG http-outgoing-229 << "Connection:close[\r][\n]"
11:41:26,803 DEBUG http-outgoing-229 << "[\r][\n]"
11:41:26,803 DEBUG http-outgoing-229 << "{"sessionId":"","status":0,"value":null}"
11:41:26,803 DEBUG http-outgoing-229 << HTTP/1.1 200 OK
11:41:26,803 DEBUG http-outgoing-229 << Content-Length:40
11:41:26,803 DEBUG http-outgoing-229 << Content-Type:application/json; charset=utf-8
11:41:26,803 DEBUG http-outgoing-229 << Connection:close
11:41:26,803 DEBUG http-outgoing-229: Close connection
11:41:26,803 DEBUG Connection discarded
11:41:26,803 DEBUG Connection released: [id: 229][route: {}->http://localhost:39283][total kept alive: 0; route allocated: 0 of 2000; total allocated: 3 of 2000]
11:41:26,803 DEBUG Closing connections idle longer than 0 SECONDS

What version of ChromeDriver are you using?

Latest Release: ChromeDriver 2.34 (Released 2017/12/10)

Supports Chrome v61- 63

Previous Releases

ChromeDriver 2.33

Supports Chrome v60-62

Also, you may need more options. Here are the ones I use:

args.add("enable-automation");
args.add("test-type=browser");
args.add("disable-plugins");
args.add("disable-infobars");

I believe at minimum you also need the "enable-automation"

You have clubbed up 2 seperate distinct errors in a single Error Stack Trace .

As per the first set of error stack trace, the error says it all as follows :

org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.className: mb12 (tried for 2 second(s) with 500 MILLISECONDS interval)

As per the errorlog the error happens in the following line :

WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("mb12")));

Here it is worth to mention that className as a locator should only be used if the class attribute is unique for the desired WebElement . If the class attribute of the desired element is not unique through visibilityOfElementLocated(By.className("mb12") Selenium will try for the visibility of the very first matching element in the HTML DOM which may not be your desired element or hidden . Hence instead of the locator className we should try to use either cssSelector or xpath (in absence of id , name , linkText , partialLinkText and tagName ).

Solution :

The solution for you would be to use either of the following :

  • cssSelector :

     WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("tagName.class#id"))); 
  • xpath :

     WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("//tagName[@class='class_values' and @id='id_value']"))); 

As per the second set of error stack trace, the error again says it all as follows :

org.openqa.selenium.WebDriverException: chrome not reachable
  (Driver info: chromedriver=2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 61.61 seconds
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:14.666Z'
System info: host: 'XXXXXX', ip: 'XXXXXXX', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_151'
Driver info: driver.version: ChromeDriver

The possible reason for that is because you are trying in a loop of 10 iterations to initiate the Chrome Browser . Due to the dangling instances of previous Chrome Browser sessions new sessions can't be initiated.

Trouble still no resolved? I use Ch v63.0.3239.132 and Chromedriver 2.35

Simplest prototype, based on your example, work fine to me. I use absolute path for loading the driver like this:

C:\\Users\\...\\IDEA Projects\\AST\\src\\main\\resources\\Drivers\\Chrome\\chromedriver.exe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM