Selenium Test (Java)--a set of element operations (11)

Source: Internet
Author: User

Use the following example to write a test script

Page code:

<! DOCTYPE html>link href= "Http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css"rel= "stylesheet"/><script src= "Http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.js" ></script>class= "Well" > <formclass= "Form-horizontal" > <divclass= "Control-group" > <labelclass= "Control-lable" for= "C1" >checkbox1</label> <divclass= "Controls" > <input type= "checkbox" id= "C1"/> </div> </div > <divclass= "Control-group" > <labelclass= "Control-lable" for= "C2" >checkbox2</label> <divclass= "Controls" > <input type= "checkbox" id= "C2"/> </div> </div > <divclass= "Control-group" > <labelclass= "Control-lable" for= "C3" >checkbox3</label> <divclass= "Controls" > <input type= "checkbox" Id= "C3"/> </div> </div > </form> </div></body>

Script:

 Packagecom.test.findelement;ImportJava.util.Iterator;Importjava.util.List;Importorg.openqa.selenium.By;ImportOrg.openqa.selenium.WebDriver;Importorg.openqa.selenium.WebElement;ImportOrg.openqa.selenium.firefox.FirefoxDriver; Public classCheckBox { Public Static voidMain (string[] args) {//TODO auto-generated Method StubWebdriver Driver=NewFirefoxdriver (); Driver.get ("File:///D:/10-selenium/workspace/SeleniumTest/src/com/test/findelement/checkbox.html");                Driver.manage (). window (). Maximize (); List<WebElement> webelements = driver.findelements (By.cssselector ("[Type=checkbox]")); Iterator Iterator=Webelements.iterator (); //Check All         while(Iterator.hasnext ()) {webelement WB=(webelement) iterator.next ();        Wb.click (); }        //Get rid of the firstWaitTime (3000); Driver.findelements (By.cssselector ("[Type=checkbox]"). Get (0). Click (); //remove the last oneWaitTime (3000); Driver.findelements (By.cssselector ("[Type=checkbox]"). Get (Webelements.size ()-1). Click (); WaitTime (5000);    Driver.quit (); }        Static  Public voidWaitTime (intTime ) {        Try{thread.sleep (time); } Catch(interruptedexception e) {//TODO auto-generated Catch blockE.printstacktrace (); }    }}

Selenium Test (Java)--a set of element operations (11)

Related Article

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.