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, However, the operation of the page is less convenient than the selenium1.0 Selenium RC API . Selenium2.0 provides a way to use the Selenium RC API :

1 //Webdriver implementation. Firefox is used hereas An example2Webdriver Driver =Newfirefoxdriver ();3  4 //A "Base url", used by selenium to resolve Relativeurls5String baseUrl = "http://www.google.com";6  7 //Create the Selenium implementation8Selenium Selenium =Newwebdriverbackedselenium (Driver, baseUrl);9  Ten //Perform actions with Selenium OneSelenium.open ("http://www.google.com"); ASelenium.type ("name=q", "cheese"); -Selenium.click ("name=btng"); -   the //Get The underlying webdriver implementation back. This willrefer to the - //same Webdriver instance as the "Driver" Variableabove. -Webdriver driverinstance =((webdriverbackedselenium) selenium). Getunderlyingwebdriver (); -   +//Finally, close thebrowser. Call stop on the Webdriverbackedselenium instance -     //instead of Callingdriver.quit (). Otherwise, the JVM would continue running after +     //The browser has beenclosed. ASelenium.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:2 Public voidLogin () {3 Driver.switchto (). Defaultcontent ();4Driver.switchto (). FRAME ("MainFrame");5  6Webelement eusername= waitfindelement (by.id ("username"));7 Eusername.sendkeys ([email protected]);8  9Webelement epassword= waitfindelement (by.id ("Password"));Ten Epassword.sendkeys (manager); One   AWebelementeloginbutton = Waitfindelement (By.id ("Loginbutton")); - Eloginbutton.click (); -   the}

1 //Login script written by SELENIUMRC API:2 Public voidLogin () {3Selenium.selectframe ("Relative=top");4Selenium.selectframe ("MainFrame");5Selenium.type ("username", "[email protected]");6Selenium.type ("Password", "manager");7Selenium.click ("Loginbutton");8 }9

Reference: selenium2.0_ Chinese help documentation. doc

Using selenium1.0 APIs 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.