Java Selenium (ix) common Web UI element operations and API usage

Source: Internet
Author: User
Tags pear xpath

Links (Link)
    <div>        <p> links link</p>        <a href= "Www.cnblogs.com/tankxiao" > Small tanks </a>    </ Div>

Linked actions

        Locate the link element        webelement link1 = driver.findelement (By.linktext ("Small Tank"));        Webelement link11 = driver.findelement (By.partiallinktext ("Tank"));                Click on the link        Link1.click ();

Input Box textbox
    <div>        <p> input box testbox</p>        <input type= "text" id= "Usernameid" value= "username"/>    </div>

Operation of the input box

        Find        the elements webelement element = Driver.findelement (By.id ("Usernameid"));                Enter the content        Element.sendkeys ("test111111") in the input box                . Empty the input box        element.clear ();                Gets the contents of the input box        element.getattribute ("value");

Buttons (Button)
    <div>        <p> button button</p>        <input type= "button" value= "Add"    id= "Proadditem_0"/> </div>

Find BUTTON Element

        Find the button element        String xpath= "//input[@value = ' add ']";        Webelement AddButton = driver.findelement (By.xpath (XPath));

        Click the button        Addbutton.click ();

        Determines whether the button is enable        addbutton.isenabled ();

Drop-Down selection box (select)
    <div>        <p> dropdown selection box select</p>        <select id= "Proadditem_kind" name= "kind" >            < Option value= "1" > PC hardware </option>            <option value= "2" > property </option>            <option value= "18" > Category aa</option>            <option value= "" > Type bb</option>            <option value= "> Category bb</ option>            <option value= > Category cc</option>        </select>    </div>

Action of the drop-down selection box

        Find element
Select select = New Select (Driver.findelement (by.id ("Proadditem_kind"));

        Select the corresponding selection, index starting from 0        Select.selectbyindex (2);        Select.selectbyvalue ("+");        Select.selectbyvisibletext ("kind AA");

        Get all the options        list<webelement> option = Select.getoptions ();        for (Webelement webelement:options) {            System.out.println (Webelement.gettext ());            }

Radio buttons (Radio button)
    <div>        <p> single option  Radio button</p>        <input type= "Radio" value= "Apple" name= "fruit > "/>apple        <input type=" Radio "value=" Pear "name=" fruit> "/>pear <input        type=" Radio " Value= "Banana" name= "fruit>"/>banana        <input type= "Radio" value= "Orange" name= "fruit>"/>orange    </div>

Actions for single-option elements

        Find the Radio box element        String xpath= "//input[@type = ' Radio '] [@value = ' Apple ']";        Webelement Apple = driver.findelement (By.xpath (XPath));

        Select a radio box        Apple.click ();

        Determines whether a radio box has been selected        Boolean isappleselect = apple.isselected ();

        Gets the element attribute        Apple.getattribute ("value");

check box with multi Marquee
    <div>        <p> Multi-option checkbox</p>        <input type= "checkbox" value= "Apple" name= "fruit>"/> Apple        <input type= "checkbox" value= "Pear" name= "fruit>"/>pear        <input type= "checkbox" Value= " Banana "Name=" fruit> "/>banana        <input type=" checkbox "value=" Orange "name=" fruit> "/>orange    </div>

The operation of the multi box is exactly the same as the radio box, which is no longer spoken.

Java Selenium (ix) common Web UI element operations and API usage

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.