idea 可以试试这个注册地址: http://intellij.mandroid.cn/
1.maven配置
下载地址:http://maven.apache.org/download.cgi#
下载内容:apache-maven-3.5.0-bin.zip
环境变量:M2_HOME:E:\Java\apache-maven-3.5.0
path:%M2_HOME%\bin;
验证:mvn --version
2.settings.xml文件
分别拷贝到以下路径:
path\to\apache-maven-3.3.3\conf
<localRepository>E:\\Java\\LocalWarehoese</localRepository><url>http://maven.aliyun.com/nexus/content/groups/public/</url>使用阿里云提供的Maven镜像服务器。阿里云镜像服务器URL:
3下载IEDriverServer、chromedriver等使用到的driver,Firefox浏览器不需要另外下载driver。
4在C盘新建一个目录Selenium, 将下载下来的driver文件放到C:\Selenium
5新建Maven项目new Project→Maven→指定maven、
setting路径:ctrl+alt+s→mavenu user settings file :apache-maven-3.3.3\conf
本地仓库路径:E:\Java\LocalWarehoese(后面两个勾都勾上,目录才会生效)
GroupId、ArtifactId 随便填Settings→Maven
6pom.xml
http://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java/3.4.0
复制Maven里面的内容,复制到pom.xml,<dependencies>里
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-firefox-driver</artifactId> <version>2.47.1</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-chrome-driver</artifactId> <version>2.47.1</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-ie-driver</artifactId> <version>2.47.1</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-htmlunit-driver</artifactId> <version>2.47.1</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-support</artifactId> <version>2.47.1</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency>7View→Tool Windows→Maven Project→刷新
不报红把
8chromedriver.exe放到resources下面
9新建test文件夹
导入点击File->Project structure在左边点击Modules在右边电击test
文件夹点击Test Sources, test 文件夹变成绿色
10加入jar包
java-client-3.1.0.jar
selenium-server-standalone-2.49.0.jar放在test下
12简单启动Chromepublic class
public class demo1 { public static void main(String[] args){ System.out.println("start firefox browser..."); System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");//指定驱动路径 WebDriver driver = new ChromeDriver(); driver.get("http://www.baidu.com/"); System.out.println("start firefox browser succeed..."); } }