Selenium2.0 the use of the Wedriver API to operate the page, its greatest advantage is that it does not need to install a selenium server to run, but the operation of the page is not as convenient as selenium1.0 selenium RC API.
SELENIUM2.0 provides a way to use the Selenium RC API:
I use the Firefox browser as an example
Webdriver Driver = new Firefoxdriver ();
String baseUrl = "http://www.google.com";
Selenium Selenium = new Webdriverbackedselenium (driver, BASEURL);
Execute Selenium command
Selenium.open ("http://www.google.com");
Selenium.type ("name=q", "cheese");
Selenium.click ("name=btng");
Webdriver driverinstance = ((webdriverbackedselenium) selenium). Getunderlyingwebdriver ();
Selenium.stop ();
Using the Webdriver API and the SELENIUMRC API to write a login script, it is clear that the latter is more straightforward to operate.
(1) Login script written by Webdriver API:
public void Login () {
Driver.switchto (). Defaultcontent ();
Driver.switchto (). FRAME ("MainFrame");
Webelement eusername= waitfindelement (by.id ("username"));
Eusername.sendkeys ([email protected]);
Webelement epassword= waitfindelement (by.id ("password"));
Epassword.sendkeys (manager);
Webelementeloginbutton = Waitfindelement (By.id ("Loginbutton"));
Eloginbutton.click ();
}
(2) Login script written by SELENIUMRC API:
public void Login () {
Selenium.selectframe ("Relative=top");
Selenium.selectframe ("MainFrame");
Selenium.type ("username", "[email protected]");
Selenium.type ("Password", "manager");
Selenium.click ("Loginbutton");
}
Using the selenium1.0 API in selenium2.0