1,之前因为进行APP自动化,因为Eclipse已经配置过了Maven
2,创建Maven项目
3.引入selenium 框架
查看maven仓库:http://mvnrepository.com/
搜素selenium java
复制到eclipse的pom。xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>come.test</groupId>
<artifactId>WebAuto</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>
</project>
4.在eclipse->src/test/java创建一个package,再创建一个class
package WebTest002; import org.openqa.selenium.chrome.ChromeDriver; public class WebAuto002 {public static void main(String []args) {
//1.打开浏览器chrome
ChromeDriver chromeDriver = new ChromeDriver();
} } 5.运行会报错,要配置webdriver。 6.下载:http://npm.taobao.org/mirrors/chromedriver/2.40/
解压chromedriver 然后复制到eclipse-》src/test/resource
7.更新代码:
package WebTest002; import org.openqa.selenium.chrome.ChromeDriver; public class WebAuto002 {
public static void main(String []args) {
System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver.exe");
//1.打开浏览器chrome
ChromeDriver chromeDriver = new ChromeDriver();
} } 8.访问个百度网页 package WebTest002; import org.openqa.selenium.chrome.ChromeDriver; public class WebAuto002 {
public static void main(String []args) {
System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver.exe");
//1.打开浏览器chrome
ChromeDriver chromeDriver = new ChromeDriver();
//2.访问百度
chromeDriver.get("http://www.baidu.com");
} } 现在第一个自动化打开页面完成!