Download
1. After downloading the JDK on the Oracle website, run Jdk.exe and install to the designated directory, after the installation completes CMD, enters the Java check whether installs successfully
2. Download Eclipse at Eclipse website
3. Firefox browser configuration firebug and Firepath
https://addons.mozilla.org/en-US/firefox/addon/firebug/
https://addons.mozilla.org/en-US/firefox/addon/firepath/
4. Download selenium various compression packages
Https://npm.taobao.org/mirrors
Need to download Selenium-server, Selenium-java package, if it is used in Google browser and download the Chromedriver package, the above URL can be found, note that the version of their own download is compatible with the version of the browser you use
Selenium-server and Firefox browser version
Chromedriver and Google browser version
Chromedriver version |
supported versions of Chrome |
v2.33 |
v60-62 |
v2.32 |
v59-61 |
v2.31 |
V58-60 |
v2.30 |
V58-60 |
v2.29 |
v56-58 |
v2.28 |
v55-57 |
v2.27 |
v54-56 |
v2.26 |
V53-55 |
v2.25 |
V53-55 |
v2.24 |
v52-54 |
v2.23 |
v51-53 |
v2.22 |
v49-52 |
v2.21 |
V46-50 |
v2.20 |
v43-48 |
v2.19 |
v43-47 |
v2.18 |
v43-46 |
v2.17 |
v42-43 |
v2.13 |
V42-45 |
v2.15 |
v40-43 |
v2.14 |
V39-42 |
v2.13 |
v38-41 |
v2.12 |
V36-40 |
v2.11 |
V36-40 |
v2.10 |
V33-36 |
v2.9 |
V31-34 |
v2.8 |
V30-33 |
v2.7 |
V30-33 |
v2.6 |
V29-32 |
v2.5 |
V29-32 |
v2.4 |
V29-32 |
Configuration
1. Configure Environment variables
New variable name java_home, variable value is the JDK installation path
New variable name classpath, variable value is.; %java_home%\lib\dt.jar;%java_home%\lib\tools.jar; (including punctuation mark all copy and paste can)
Add variable value after variable name path;%java_home%\bin;
2. Create a new Java project, package, class file in Eclipse, check the main method when you create a new Claa file, select the project right key after the new success Properties--java build Path--libraries--add External JARs
The selenium-java-version number, the jar and the Libs folder, and the selenium-server-version number, are under the import download Selenium-java package. jar
Run
Note Start the selenium server before each run
CMD--CD to the folder where Selenium-server resides
Then Java-jar Selenium-server-standalone-2.42,2.jar
If you do not start Selenium server eclipse will complain:
Exception in thread "main" java.lang.RuntimeException:Could not contact Selenium Server; Have you started it on ' localhost:4444 '?
Read more at http://seleniumhq.org/projects/remote-control/not-started.html
Connection Refused:connect
At Com.thoughtworks.selenium.DefaultSelenium.start (defaultselenium.java:104)
At Demo.demo3.main (demo3.java:12)
Problems encountered
1. Using the Firefox browser, the browser does not start after running and does not complain, because the selenium version is incompatible with the Firefox version
2. No Google driver set, webdriver Driver = new Chromedriver (), Error, resolution:
Add System.setproperty ("Webdriver.chrome.driver", "C:\\java\\chromedriver_win3\\chromedriver.exe");
Set Google's drive, which is the chromedriver.exe,c:\\java\\chromedriver_win3\\chromedriver.exe of the previous download changed to its own path
3. Open Google Browser and do not enter the Url,url column display data and prompted "You are using an unsupported command line tag:--ignore-certificate-errors." Stability and security will decrease. ' Workaround:
Add options.addarguments ("--user-data-dir=c:/users/administrator/appdata/local/google/chrome/user Data/Default"); parameter to prohibit data;
Add options.addarguments ("--start-maximized", "Allow-running-insecure-content", "--test-type"); Tips for removing stability
A section of open Baidu Demo:
Package demo;
Import Java.util.concurrent.TimeUnit;
Import Org.openqa.selenium.By;
Import Org.openqa.selenium.WebDriver;
Import Org.openqa.selenium.chrome.ChromeDriver;
Import org.openqa.selenium.chrome.ChromeOptions;
public class Demo5 {public
static void Main (string[] args) {
Webdriver driver = null;
Chromeoptions options = new Chromeoptions ();
The presence of data is prohibited by configuration parameters
Options.addarguments ("--user-data-dir=c:/users/administrator/appdata/local/google/ Chrome/user Data/default ");
Removing stability and security by configuring parameters indicates a decrease in
options.addarguments ("--start-maximized", "allow-running-insecure-content", "- Test-type ");
Set up to start Google Drive
system.setproperty ("Webdriver.chrome.driver", "C:\\java\\chromedriver_win3\\chromedriver.exe");
Driver=new chromedriver (options);
Driver.manage (). Timeouts (). implicitlywait (2, timeunit.seconds);
Driver.navigate (). to ("http://www.baidu.com/");
}