目录
The version of ChromeDriver only support xxxxxxxxx
The path to the driver executable the path to
windows电脑环境搭建+Chrome谷歌浏览器
谷歌浏览器下载官网:https://www.google.cn/intl/zh-CN/chrome/
查看chrome浏览器版本
注意点:因为Selenium下载的浏览器驱动版本必须与浏览器版本保持一致才能运行成功,但是Google浏览器都会默认自动更新版本,这样就会导致已经下载好的浏览器驱动与浏览器版本不一致
解决方法:禁止Google浏览器自动更新
方法一:下载无更新组件的Google浏览器(版本113),下载链接见:https://zhuanlan.zhihu.com/p/628088190
方法二:设置更新服务为禁止状态,链接见: https://jingyan.baidu.com/article/59a015e36f6350f794886507.html
下载Chrome浏览器驱动
下载链接1(官网链接,国内访问很慢,推荐使用梯子):chromedriver.chromium.org
下载链接2(不需要使用梯子,推荐使用):chromedriver.storage.googleapis.com/index.html
配置环境变量
解压下载好的驱动压缩包,将下载好的chromedriver.exe放到java的jdk系统环境变量下
1.在运行窗口输入cmd,进入命令窗口,输入java -verbose 并回车。
2.在输出信息的最后一行你会看到你的jdk安装路径。如图:
3.将下载的谷歌驱动exe文件放在jdk路径下的bin路径下
验证环境是否搭建成功
创建项目成功之后在pom.xml文件里面配置依赖:
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>4.4.1</version>
</dependency>
</dependencies>
在java里面的main路径下创建一个Test类来编写代码:
public class Test {
public static void main(String[] args) {
//导入google驱动
WebDriver webDriver = new ChromeDriver();
//驱动去输入指定网址
webDriver.get("https://www.baidu.com");
}
}
运行代码,如果出现以下界面则创建 成功
常见问题&解决办法
The version of ChromeDriver only support xxxxxxxxx
The path to the driver executable the path to
原因:浏览器驱动没有放到系统环境变量下
解决方法:确认自己安装的JDK版本,可以查看idea创建项目时所使用的的JDK版本,找到安装路径,将驱动放到对应路径下,前面配置环境步骤已详细介绍