First, the development environment:
1, JDK1.6
2. Eclipse:Version:Kepler Service Release 1,:http://www.eclipse.org/downloads/
3, Selenium:selenium-java-2.39.0.zip,:http://code.google.com/p/selenium/downloads/list
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.
1 package Com.selenium.Glen; 2 3 import org.openqa.selenium.By; 4 import org.openqa.selenium.WebDriver; 5 import org.openqa.selenium.WebElement ; 6 Import org.openqa.selenium.firefox.*; 7 8 public class Testhelloworld {9 -public static void main (string[] args) {One -to-one//If Firefox is not installed by default on the C drive, you need to To develop its path to //system.setproperty ("Webdriver.firefox.bin", "D:/program Files/mozilla Firefox/firefox.exe"); 14 Webdriver Driver = new Firefoxdriver (); driver.get ("http://www.baidu.com/"); Driver.manage (). window (). Maximize (), webelement txtbox = driver.findelement (By.name ("WD")); Txtbox.sendkeys ("Glen"), webelement btn = driver.findelement (by.id ("su")); Btn.click (); 24 driver.close (); }28 29}
Then directly right-click-->run As-->java application can see the effect.
SELENIUM2 (webdirver) Getting Started Environment Building (Java Edition)