The acitons of the element

Source: Internet
Author: User

Different page elements have different actions

1, SendKeys ()

Applies to page elements that have a text editing area. A common use is to enter a string in a text box. The sample code is as follows:

Webelement SearchBox = driver.findelement (By.name ("Q"));

searchbox. SendKeys ("Webdriver");

If you want to enter some special characters in the text box, such as shift, you need to use the keys class in Webdriver. Keys is an array class that simulates a number of different special key input types. For example, the letters you want to enter are capitalized, and the manual way is to press the SHIFT key to enter the appropriate letters. To use the keys to achieve this effect, the sample code is as follows:

Webelement searchbox = driver.findelement (By.name ("Q"));

Searchbox.sendkeys (Keys.chord (keys). SHIFT, "Webdriver"));

2. Clear ()

Applies to page elements with a text editing area, which clears the text information entered in the text editing area.

Webelement SearchBox = driver.findelement (By.name ("Q"));

Serachbox. Clear ();

3. Submit ()

Applies to page elements in a form or form, by submitting a form to the Web server side. The sample code is as follows:

Webelement SearchBox = driver.findelement (By.name ("Q"));

searchbox. Submit ();

4, isdisplayed ()

Applies to any page element that determines whether the element is visible on the page. The sample code is as follows:

Webelement searchbox = driver.findelement (By.name ("BTNK"));

System.out.println (searchbox. Displayed ());

5, IsEnabled ()

Applies to any page element that determines whether the element is enabled. The sample code is as follows:

Webelement SearchButton = driver.findelement (By.name ("BTNK"));

System.out.println (searchbutton.isenabled ());

6, isSelected ()

Applies to page elements, such as radio buttons, multi-select buttons, and options, to determine whether an element is selected. If the method is called on another page element, the program returns False, as shown in the following example code:

Webelement SearchButton = driver.findelement (By.name ("BTNK"));

System.out.println (RadioButton. isSelected ());

7, GetAttribute ()

Applies to any page element that gets the properties of the current page element. For example, the HTML code for search buttons in google pages

<input value= "Google Search" jsaction= "Sf.chk" name= "BTNK" type= "Submit" >

If the element has been found through the name of the search button and you want to get its value, the sample code is as follows:

Webelement searchbutton = driver.findelement (By.name ("BTNK"));

System.out.println ("Value of the Bytton is:" +SearchButton. getattribute ("value"));

8, GetText ()

Applies to any page element that gets the visible text content on the element. If the text content is empty, the method returns NULL. The sample code is as follows:

Webelement SearchButton = driver.findelement (By.name ("BTNK"));

System.out.println (SearchButton. GetText ());

9, Gettagname ()

Applies to any page element that gets the tag name of the element. For example, the HTML of the Google search button is as follows, where input is the tag name of the search button

<input value= "Google Search" jsaction= "Sf.chk" name= "BTNK" type= "Submit" >

If the element has been found through the name of the search button and you want to get its tag name value, the sample code is as follows:

Webelment SearchButton = driver.findelement (By.name ("BTNK"));

System.out.println (SearchButton. Gettagname ());

10, Getcssvalue ()

Applies to any page element that gets the CSS properties of the current page element, such as cursor, font-family, font-size, and so on, as shown in the sample code:

Webelement searchbutton = driver.findelement (By.name ("BTNK"));

System.out.println (SearchButton. Getcssvalue ("height"));

11, GetLocation ()

Applies to any page element that gets the relative position of the element in the page, where the coordinate system origin is located in the upper-left corner of the page. The return value of the method is a coordinate information that includes (x, y), as shown in the example code

Webelement SearchButton = driver.findelement (By.name ("BTNK"));

System.out.println (SearchButton. getLocation ());

12, GetSize ()

Applies to any visible page element that gets the width and height information of an element, and its return value is a long-width combination that includes (width,height), the sample code is as follows:

Webelment SearchButton = driver.findelement (By.name ("BTNK"));

System.out.println (SearchButton. GetSize ());

The acitons of the element

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.