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

Source: Internet
Author: User

Use the following example to write a test script

Page code:

1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <Metahttp-equiv= "Content-type"content= "Text/html;charset=utf-8" />5 <title>CheckBox</title>6 <Link7     href= "Http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css"8 rel= "stylesheet" />9 <ScriptTen     src= "Http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.js"></Script> One </Head> A <Body> -     <H3>CheckBox</H3> -     <Divclass= "Well"> the         <formclass= "Form-horizontal"> -             <Divclass= "Control-group"> -                 <labelclass= "Control-lable" for= "C1">CheckBox1</label> -                 <Divclass= "Controls"> +                     <inputtype= "checkbox"ID= "C1" /> -                 </Div> +             </Div> A             <Divclass= "Control-group"> at                 <labelclass= "Control-lable" for= "C2">CheckBox2</label> -                 <Divclass= "Controls"> -                     <inputtype= "checkbox"ID= "C2" /> -                 </Div> -             </Div> -             <Divclass= "Control-group"> in                 <labelclass= "Control-lable" for= "C3">Checkbox3</label> -                 <Divclass= "Controls"> to                     <inputtype= "checkbox"ID= "C3" /> +                 </Div> -             </Div> the         </form> *     </Div> $ </Body>Panax Notoginseng </HTML>

Script:

1 Package com.test.findelement;2 3 import Java.util.Iterator;4 import java.util.List;5 6 import org.openqa.selenium.By;7 import Org.openqa.selenium.WebDriver;8 import org.openqa.selenium.WebElement;9 import Org.openqa.selenium.firefox.FirefoxDriver;Ten  One Public class CheckBox { A  - Public static void Main (string[] args) { - //TODO auto-generated method stub the          - Webdriver Driver = new Firefoxdriver (); - 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]")); +          A Iterator Iterator = Webelements.iterator (); at          - //Check all - While (Iterator.hasnext ()) { - webelement wb = (webelement) iterator.next (); - Wb.click (); -         } in //Get rid of the first - WaitTime (+); to driver.findelements (By.cssselector ("[Type=checkbox]")). Get (0). Click (); +          - //Remove the last one the WaitTime (+); * driver.findelements (By.cssselector ("[Type=checkbox]")). Get (Webelements.size ()-1). Click (); $         Panax Notoginseng          - WaitTime (the); the driver.quit (); +     } A      the static public void waitTime (int time) { +  - try { $ Thread.Sleep (time); $ } catch (Interruptedexception e) { - //TODO auto-generated catch block - e.printstacktrace (); the         } -     }Wuyi  the}

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.