Table of Contents
一、Selenium 是一个用于Web应用程序自动化测试工具。
2.2 下载 chrome 驱动 chromedriver.exe
参考:https://blog.csdn.net/qq_22003641/article/details/79137327
本文介绍的是小部分。
一、Selenium 是一个用于Web应用程序自动化测试工具。
二、注意事项
2.1 google 安装路径
Linux | /usr/bin/google-chrome1 |
Mac | /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome |
Windows XP | %HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe |
Windows Vista | C:\Users%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe |
2.2 下载 chrome 驱动 chromedriver.exe
https://sites.google.com/a/chromium.org/chromedriver/downloads
注:每个浏览器的驱动都不同哦。需要下载与chrome版本一致的驱动哦。
三、通过Maven配置Selenium
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-alpha-2</version>
</dependency>
四、创建测试类
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
/**
* Created by IntelliJ IDEA.
*
* @author NingZe
* description: selenium-java
* date: 2019/7/22 0022 11:07
* version: 02.06
* To change this template use File | Settings | File Templates.
*/
public class SeleniumJava {
public static void main(String[] args) throws InterruptedException {
// 设置系统属性(1. 属性名 2. chrome 驱动路径)
System.setProperty("webdriver.chrome.driver", "D:\\driver\\chromedriver.exe");
// 创建浏览器对象
WebDriver driver= new ChromeDriver();
// 打开页面
driver.get("https://www.baidu.cn");
// 窗口最大化
driver.manage().window().maximize();
// 休眠2秒
Thread.sleep(2000);
// 打开页面
driver.get("https://m.baidu.cn");
// 窗口指定大小
driver.manage().window().setSize(new Dimension(480, 800));
// 休眠2秒
Thread.sleep(2000);
// 关闭浏览器
driver.quit();
}
}
运行时如果出现
Unsupported major.minor version 52.0
证明 JDK 小于 8,更换 JDK 版本即可。