First, the Environment configuration
1, download selenium-java-2.53.0, and unzip, download Selenium-server-standalone-2.53.1.jar (official website download)
2. Download the latest version of Eclipse (version:neon.1a release (4.6.1)) website
3, install the JDK (1.8 version), I previously loaded is 1.7, does not support the latest version of Eclipse, had to unload load 1.8
4, Firefox 45 (to use the lower version of Firefox, otherwise incompatible with the selenium2, resulting in unable to fall)
Ii. Creation of the project
1. Open eclipse-> New Project tests
2, Import Selenium-java-2.53.0.jar, Selenium-server-standalone-2.53.1.jar (step: Project name right button->build Path->add Libraries)
3, the new class SELENIUMCN, the code is as follows
Package Tests;import Org.openqa.selenium.By; Import Org.openqa.selenium.WebDriver; Import org.openqa.selenium.WebElement; Import Org.openqa.selenium.firefox.FirefoxDriver; public class SELENIUMCN {publicstatic void main (string[] args) { system.setproperty ("Webdriver.firefox.bin", "c:/ Program Files (x86)/mozilla Firefox/firefox.exe "); Webdriver Driver = new Firefoxdriver (); Driver.get ("http://www.baidu.com"); webelement element = Driver.findelement (By.name ("WD")); Element.sendkeys ("Hello selenium!"); Element.submit (); try { thread.sleep; } catch (Interruptedexception e) { e.printstacktrace (); } System.out.println ("page title is:" + driver.gettitle ());//Print the title of the page to make it easier to know whether to complete the search driver.quit ();}}
Third, the operation
1. Open Firefox, open Baidu, enter Hello selenium!
2. Running Result: Page title Is:hello selenium!_ Baidu Search
Windows7 Selenium2+java Construction