当我在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中启动了一个新的会话,但随后抛出了异常。任何帮助都将不胜感激。
发布于 2016-09-20 14:59:07
我认为你点击的是程序可执行文件而不是驱动程序。
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();它应该是chrome驱动程序的路径,而不是chrome浏览器可执行文件的路径。你可以看看https://sites.google.com/a/chromium.org/chromedriver/getting-started
https://stackoverflow.com/questions/39586563
复制相似问题