SELENIUM2 (webdirver) Getting Started Environment Building (Java Edition)
First, the development environment:
1, JDK1.6
2. Eclipse:Version:Kepler Service Release 1,:http://www.eclipse.org/downloads/
3, selenium:selenium-java-2.52.0.zip,:http://docs.seleniumhq.org/download/
Unpack the Selenium-java package, which contains four parts, such as:
Second, create a new Java Project:
1, then the above extracted files copied to the new project directory, directory structure such as:
2. Add build path, project directory right click-->build path--> Config build Path-->java build Path-->libraries-->add JARs
Add all the jar packages under the Libs folder and add selenium-java-2.39.0 and Selenium-java-2.39.0-srcs
3, add after the directory structure, such as, more referenced Libraries, here is the above step added to the jar package:
4, the source of related webdriver:
Now that the environment is ready to work, here is a simple little example to write.
III. Create a new test class under SRC, such as:
The code below, mainly open Baidu, and then enter Glen in the Search box, click the Search button, close the browser.
1PackageCom.selenium.Glen;23ImportOrg.openqa.selenium.By;4ImportOrg.openqa.selenium.WebDriver;5ImportOrg.openqa.selenium.WebElement;6Import org.openqa.selenium.firefox.*;78PublicClassTesthelloworld {910PublicStaticvoidMain (string[] args) {1112//If Firefox is not installed by default on the C drive, you need to set its path13//System.setproperty ("Webdriver.firefox.bin", "D:/program Files/mozilla firefox/firefox.exe");Webdriver Driver =NewFirefoxdriver ();Driver.get ("http://www.baidu.com/");16 17 Driver.manage (). Window (). Maximize (); 18 19 webelement txtbox = driver.findelement (By.name ("WD" 20 txtbox.sendkeys ("Glen" 22 webelement btn = driver.findelement (by.id ("su" 23 Btn.click (); 25 Driver.close (); 27 }28 29}
Then right-click-->run As-->java application to see the effect.
Selenium Java Environment setup