selenium学习笔记之启动谷歌浏览器

代码:


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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容