我在chrome中尝试以下代码时收到UnhandledBrowserException:
公共类myClass {
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty("webdriver.chrome.driver", "C://Program Files (x86)//Google//Chrome//Application//chrome.exe");
WebDriver driver= new ChromeDriver();
String baseURL = "http://newtours.demoaut.com";
String expectedTitle = "Welcome: Mercury Tours";
String actualTitle = "";
// launch Firefox and direct it to the Base URL
driver.get(baseURL);
// get the actual value of the title
actualTitle = driver.getTitle();
/*
* compare the actual title of the page witht the expected one and print
* the result as "Passed" or "Failed"
*/
if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
//close Firefox
driver.close();
// exit the program explicitly
System.exit(0);
}
它正在chrome中启动一个新会话,但随后抛出异常。任何帮助都将受到高度赞赏。
答案 0 :(得分:0)
我认为您正在使用程序可执行文件而不是驱动程序。
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();
它应该是chrome驱动程序的路径而不是chrome浏览器可执行文件。 您可以查看https://sites.google.com/a/chromium.org/chromedriver/getting-started