代码:
package test02;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestChrome {
public void test03() {
System.setProperty("webdriver.chrome.driver", "E:\\chromedriver.exe");
System.setProperty("webdriver.chrome.bin", "C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");
WebDriver driver3 = new ChromeDriver();
driver3.get("http://www.baidu.com");
driver3.findElement(By.id("kw")).sendKeys("刘心武揭秘红楼梦");
driver3.findElement(By.id("su")).click();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
driver3.quit();
}
}
运行后报错,报错内容为:Error communicating with the remote browser. It may have died.
浏览器启动后无法代开百度页面,如图:
查找前人经验后是由于谷歌浏览器的驱动和版本是有匹配的,我的浏览器是最新下载的57版本,故下载了最新的Chromedriver,将原来的Chromedrive替换掉,重新运行,成功运行
Chrome下载地址:http://npm.taobao.org/mirrors/chromedriver/
http://chromedriver.storage.googleapis.com/index.html