我在1周后面临上述问题。早些时候,它运作顺利。即使现在有时它工作正常,但大多数时候我得到“无法连接到localhost /”错误。 :(我已将Chrome驱动程序升级到2.37,现在将其降级为2.36,但没有运气。:(谢谢。
问题详细信息:java.net.ConnectException:无法连接到localhost / 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',os.name:'Windows 8.1',os.arch:'amd64',os.version :'6.3',java.version:'1.8.0_131'驱动程序信息:driver.version:RemoteWebDriver
以下是供您参考的代码:注意:它可以正常工作直到登录。只有当我尝试在登录后搜索某个元素时才会出现问题。
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未被识别为:
Driver info: driver.version: RemoteWebDriver
您的主要问题是您使用的二进制文件之间的版本兼容性如下:
因此,JDK v8u131,Selenium Client v3.11.0,ChromeDriver版本(v2.37)之间存在明显的不匹配。
@Test
。看看你在哪里实例化驱动器。您写道:System.setProperty(“webdriver.chrome.driver”,“d://chromedriver.exe”);
我认为问题在于镀铬驱动路径。试试:“D:/chromedriver.exe”);
定义路径时应该只有一个正斜杠。