ChromeDriver:Chrome浏览器驱动)79.0.3945.36   81.0.4044.138    83.0.4103.39    78.0.3904.105   

官网地址:https://npm.taobao.org/mirrors/chromedriver/    

GeckoDriver:Firefox浏览器驱动)v0.26.0   

官方网址:https://npm.taobao.org/mirrors/geckodriver/   

一、下载对应的驱动版本,放在一个公共目录中,比如放在《C:\Users\Public\WebDriver》下:

注:可以把当前目录加到Path中,这样就不需要每次加 webdriver.chrome.driver 等参数设置。


二、在Maven项目中下载Jar,pom.xml文件配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>test-selenium</groupId><artifactId>test-selenium</artifactId><version>1.0-SNAPSHOT</version>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId>
				<version>3.8.0</version>
				<configuration><source>1.8</source><target>1.8</target><encoding>UTF-8</encoding></configuration>
			</plugin>
		</plugins>
	</build>
	<dependencies>
		<dependency>
			<groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-java</artifactId><version>3.141.59</version>
		</dependency>
		<dependency>
			<groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-server</artifactId><version>3.141.59</version>
		</dependency>
		<dependency>
			<groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-firefox-driver</artifactId><version>3.141.59</version>
		</dependency>
		<dependency>
			<groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-chrome-driver</artifactId><version>3.141.59</version>
		</dependency>
		<dependency>
			<groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-remote-driver</artifactId><version>3.141.59</version>
		</dependency>
		<dependency>
			<groupId>com.google.guava</groupId><artifactId>guava</artifactId><version>28.2-jre</version>
		</dependency>
	</dependencies>
</project>
三、直接使用Jar包导入:

selenium_java_3.141.59.zip   解压后,有如下Jar包:

四、一个简单的打开浏览器、打开一个网站的代码:

  public static void main(String[] args) {
//      System.setProperty("webdriver.firefox.marionette", "C:\\Users\\Public\\WebDriver\\geckodriver.exe");
//      WebDriver driver = new FirefoxDriver();
      System.setProperty("webdriver.chrome.driver", "C:\\Users\\Public\\WebDriver\\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      driver.manage().window().maximize();//最大化浏览器
      driver.get("https://www.mchweb.net");
      driver.quit();
  }


附A:各种浏览器WebDriver驱动下载:

Browser
Component
Chrome
chromedriver
Internet Explorer
IEDriverServer
Edge
EdgeWebDriver
Firefox 47+
geckodriver
PhantomJS
phantomjs
Opera
operadriver
Safari
SafariDriver