java - chrome浏览器和selenium异常

标签 java google-chrome selenium

我的 java 代码收到以下异常。我想做的就是打开一个 chrome 浏览器。我已经下载了正确的 chrome 驱动程序并将其粘贴在程序文件 x86 下的 google chrome 文件夹中。现在发生的情况是,浏览器打开,然后立即说程序已停止工作,然后一旦我单击窗口上的退出,它就会抛出异常。

Starting ChromeDriver 2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067) on port 23239
Only local connections are allowed.
Exception in thread "main"   org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new  session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'W7LPC01TDFU', ip: '10.95.7.58', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_79'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665)

这是我到目前为止的代码

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class mainTester {


public static void main(String[] args) throws InterruptedException{

    setUp();
}
public static void setUp() throws InterruptedException {
      // Optional, if not specified, WebDriver will search your path for chromedriver.
      System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");

      WebDriver driver = new ChromeDriver();
      driver.get("http://www.google.com/xhtml");
      Thread.sleep(5000);  // Let the user actually see something!
      WebElement searchBox = driver.findElement(By.name("q"));
      searchBox.sendKeys("ChromeDriver");
      searchBox.submit();
      Thread.sleep(5000);  // Let the user actually see something!
      System.out.println("Finished");
      driver.quit();

    }

}

最佳答案

您知道您使用的是哪个版本的 Chrome 吗?机会是最新的,因为谷歌喜欢自动更新。您应该使用最新版本的 Chromedriver。您发布的回溯表明您使用的是版本 2.20(在端口 23239 上启动 ChromeDriver 2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067))。最新的是2.25,支持Chrome v53-55

关于java - chrome浏览器和selenium异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41020627/

相关文章:

java - Android 位置时间到日期

java - 如何通过 Intent 发送 Map<String, List<String>>

javascript - 如何在chrome开发者工具中添加伪元素?

java - Selenium 多浏览器测试。只有最后一个浏览器会收到 cookie。测试NG

Java 错误 : "Could not find or load main class .ie.driver" with selenium

Java 线程 JavaDoc

reactjs - 不断收到警告 : Invalid DOM property `autocomplete` . 您的意思是 `autoComplete` 吗?

javascript - 从 chrome 开发者工具中取消 ajax 请求

java - 如何断言图像是否在 Selenium 中放大

java - 如何将时间与我的 table 匹配?