如何解决"org.openqa.selenium.WebDriverException:java.net.ConnectException:无法连接到localhost/".与谷歌驱动程序? [英] How to resolve " org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/" with google driver?

查看:797
本文介绍了如何解决"org.openqa.selenium.WebDriverException:java.net.ConnectException:无法连接到localhost/".与谷歌驱动程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自1周以来,我一直面临上述问题.早些时候,它运行顺利.即使是现在,有时它仍然可以正常工作,但是在大多数情况下,我会收到"无法连接到本地主机/"错误. :( 我已经将chrome驱动程序升级到2.37,现在再次将其降级到2.36,但是没有运气. :(谢谢.

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.

问题详细信息: java.net.ConnectException:无法连接到localhost/0:0:0:0:0:0:0:0:1:4321 构建信息:版本:'3.11.0',修订版本:'e59cfb3',时间:'2018-03-11T20:33:15.31Z' 系统信息:主机:'GURWUNknjk',ip:'10 .202.126.154',操作系统名称:'Windows 8.1',os.arch:'amd64',os.version:'6.3',java.version:'1.8.0_131 ' 驱动程序信息:driver.version:RemoteWebDriver

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(); }

推荐答案

错误说明了一切:

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

该错误清楚地表明 ChromeDriver 无法识别为:

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 :

  • 您正在使用 chromedriver = 2.37
  • 您不知道您的 chrome 版本.
  • 您的 Selenium Client 版本是 3.11.0 .
  • 您的 JDK版本 1.8.0_131 ,这很古老.
  • 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.

因此 JDK v8u131 Selenium Client v3.11.0 ChromeDriver 版本( v2.37 ).

  • JDK 升级到最新级别 JDK 8u162 .
  • 在当前ChromeDriver "rel =" nofollow noreferrer> ChromeDriver v2.37 级别.
  • 保持 Chrome 版本处于 Chrome v65.x 级别. (根据ChromeDriver v2.37发行说明)
  • 通过 IDE
  • 清理您的项目工作区重建您的项目,并且仅具有必需的依赖项.
  • 使用 CCleaner 工具清除之前和之后的所有操作系统杂项在执行 test Suite 之后.
  • 如果您的基本 Web客户端版本太旧,请通过来卸载. Revo Uninstaller 并安装最新版本的 Web客户端 GA和发行版.
  • 进行系统重启.
  • 执行您的@Test.
  • 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.

这篇关于如何解决"org.openqa.selenium.WebDriverException:java.net.ConnectException:无法连接到localhost/".与谷歌驱动程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆