package org.testngsessions;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestRegist {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\Asus\\Desktop\\chromedriver.exe");
WebDriver driver= new ChromeDriver();
driver.get("http://automationpractice.com/");
System.out.println(driver.getTitle());
}
}
此代码无法打开谷歌浏览器。我究竟做错了什么?在eclipse中我得到只允许本地连接。
错误:
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException:
答案 0 :(得分:0)
将您的驱动程序版本更改为" chromedriver-2.35"
答案 1 :(得分:0)
我已经下载了最新的2.40镀铬驱动程序,您的代码也适用于我。
所以你可能遇到驱动程序问题或者如果使用maven,请尝试更新你的客户端/服务器
// client //
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.12.0</version>
</dependency>
// //服务器
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.12.0</version>
</dependency>
并在此处查看最新的Chrome驱动程序: http://chromedriver.chromium.org/
希望这有帮助,
标题说:System.out.println(driver.getTitle());
&#34;我的商店&#34; :)
答案 2 :(得分:0)
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--no-sandbox");
WebDriver driver= new ChromeDriver(chromeOptions);
在上面的代码中使用带有“ no-sandbox”选项的chrome驱动程序。它将起作用。希望对您有帮助。