Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Actions of the WebDriver- element

Shulou Source: shulou.com Published: 2022-06-03 05:40:57 11月24日 Update

1.sendKeys ()

Applies to page elements that have text editing areas. A common way to use it is to enter a string in the text box.

Driver.findElement (By.xpath ("html/body/div [8] / div/div/input"). SendKeys ("150")

If you want to enter some special characters, such as Shift, in the text box, you need to use the Keys class in WebDriver. Keys is an array class that simulates a variety of different special keystrokes. For example, if you want to enter uppercase letters, the manual way is to hold down the shift key and then enter the corresponding letters.

WebElement we1 = driver.findElement (By.xpath (". / / * [@ id='EXAM'] / div [1] / h5CMI"))

We1.sendKeys (Keys.chord (Keys.SHIFT, "webdriver"))

2.clear ()

Suitable for page elements with a text editing area to clear text information entered in the text editing area.

WebElement we1 = driver.findElement (By.xpath (". / / * [@ id='EXAM'] / div [1] / h5CMI"))

We1.clear ()

3.submit ()

Applies to page elements in form or form to submit form to the server side of Web.

WebElement we1 = driver.findElement (By.xpath (". / / * [@ id='EXAM'] / div [1] / h5CMI"))

We1.submit ()

4.isDisplayed ()

Applies to any page element and is used to determine whether the element is visible on the page.

WebElement we1 = driver.findElement (By.xpath (". / / * [@ id='EXAM'] / div [1] / h5CMI"))

System.out.println (we1.isDisplayed ())

5.isEnabled ()

Applies to any page element and is used to determine whether the element is enabled.

WebElement we1 = driver.findElement (By.xpath (". / / * [@ id='EXAM'] / div [1] / h5CMI"))

System.out.println (we1.isEnabled ())

6.isSelected ()

Suitable for 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.

WebElement we1 = driver.findElement (By.xpath (". / / * [@ id='EXAM'] / div [1] / h5CMI"))

System.out.println (we1.isSelected ())

7.getAttribute ()

Applies to any page element and is used to get the attributes of the current page element.

WebElement aboutGenExam = driver.findElement (By.linkText ("contact us"))

System.out.println (aboutGenExam.getAttribute ("value"))

8.getText ()

Suitable for any page element to get the visible text content on the element. If the text content is empty, it returns empty.

WebElement aboutGenExam = driver.findElement (By.linkText ("contact us"))

System.out.println (aboutGenExam.getText ())

9.getTagName ()

Applies to any page element and is used to get the tag name of the element.

WebElement aboutGenExam = driver.findElement (By.linkText ("contact us"))

System.out.println (aboutGenExam.getTagName ())

10.getCssValue ()

It is suitable for any page element and is used to obtain the CSS attribute information of the current page element, such as: cursor\ font-family\ font-size\ height\ background-color\ background-p_w_picpath, etc.

WebElement aboutGenExam = driver.findElement (By.linkText ("contact us"))

System.out.println (aboutGenExam.getCssValue ("height"))

11.getLocation ()

Suitable for any page element, used to obtain the relative position of the element on the page, where the coordinate system origin is located in the upper-left corner of the page. The return value of this method is a coordinate information that includes (xPowery).

WebElement aboutGenExam = driver.findElement (By.linkText ("contact us"))

System.out.println (aboutGenExam.getLocation ())

12.getSize ()

Suitable for any visible page element, used to obtain the width and height information of the element. The return value is a combination of length and width that includes (width,height).

WebElement aboutGenExam = driver.findElement (By.linkText ("contact us"))

System.out.println (aboutGenExam.getSize ())

Tags: Element page text contact input information region special function content coordinates letters characters attributes buttons methods different location origin Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple OPPO Reno NVidia Huawei Shulou Technology