How to resolve “ org.openqa.selenium.WebDriverExce

2019-01-25 23:43发布

I am facing above mentioned issue since 1 week. Earlier it was working smoothly. Even now sometimes it works fine but most of the time I am getting "Failed to connect to localhost/" error. :( I have upgraded chrome driver to 2.37 now downgraded it again to 2.36 but no luck. :( Thanks.

Issue details: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:4321 Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:15.31Z' System info: host: 'GURWUNknjk', ip: '10.202.126.154', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_131' Driver info: driver.version: RemoteWebDriver

Here is code for your reference: Note : It works fine till login. Issue comes only when I try to search some element after login.

    public static WebDriver driver;
    public static void main(String[] args) throws InterruptedException, IOException {
                System.setProperty("webdriver.chrome.driver", "d://chromedriver.exe");
        driver = new ChromeDriver();
        String url = "https://accounts.google.com/signin/v2/identifier?continue=https%3A%2F%2Faccounts.google.com%2Fb%2F0%2FAddMailService&flowName=GlifWebSignIn&flowEntry=AddSession";
        driver.get(url);

driver.manage().window().maximize();
        WebDriverWait wait = new WebDriverWait(driver, 20);
        driver.manage().timeouts().implicitlyWait(15,TimeUnit.SECONDS) ;

        wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[type='Email']")));

        if(driver.getCurrentUrl().contains("https://accounts.google.com/signin/v2/identifier?"))
        {

            driver.findElement(By.id("identifierId")).sendKeys(username);
            driver.findElement(By.id("identifierNext")).click();        wait.until(ExpectedConditions.presenceOfElementLocated(By.name("password"))); 
            driver.findElement(By.name("password")).sendKeys(pwd);
            driver.findElement(By.name("password")).sendKeys(Keys.ENTER);
        }
        else{
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[type='Email']")));
            driver.findElement(By.name("Email")).sendKeys(UserName);
            driver.findElement(By.id("next")).click();           wait.until(ExpectedConditions.presenceOfElementLocated(By.name("Passwd")));
            driver.findElement(By.name("Passwd")).sendKeys(Pwd);
                    wait.until(ExpectedConditions.presenceOfElementLocated(By.name("signIn")));
 driver.findElement(By.id("signIn")).click();
           }
wait.until(ExpectedConditions
                    .visibilityOfElementLocated(By.id(element id)));
            driver.findElement(By.id(element id))
            .sendKeys(some value);
            Thread.sleep(3000);
            driver.findElement(By.id(element id)).click(); }

2条回答
叛逆
2楼-- · 2019-01-26 00:05

Take a look at where you are instantiating the drive. You wrote: System.setProperty("webdriver.chrome.driver", "d://chromedriver.exe");

I believe the issue is with the chrome drive path. Try: "D:/chromedriver.exe");

There should be only one forward slash when defining the path.

查看更多
该账号已被封号
3楼-- · 2019-01-26 00:16

The error says it all :

java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:4321 
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:15.31Z' 
System info: host: 'GURWUNknjk', ip: '10.202.126.154', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_131' 
Driver info: driver.version: RemoteWebDriver

The error clearly shows that the ChromeDriver was not recognized as in :

Driver info: driver.version: RemoteWebDriver

Your main issue is the version compatibility between the binaries you are using as follows :

  • You are using chromedriver=2.37
  • Your chrome version is unknown to us.
  • Your Selenium Client version is 3.11.0.
  • Your JDK version is 1.8.0_131 which is pretty ancient.

So there is a clear mismatch between the JDK v8u131 , Selenium Client v3.11.0 , ChromeDriver version (v2.37).

Solution

  • Upgrade JDK to recent levels JDK 8u162.
  • Keep ChromeDriver at current ChromeDriver v2.37 level.
  • Keep Chrome version at Chrome v65.x levels. (as per ChromeDriver v2.37 release notes)
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • Use CCleaner tool to wipe off all the OS chores before and after the execution of your test Suite.
  • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Execute your @Test.
查看更多
登录 后发表回答