Using the selenium1.0 API in selenium2.0

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.