Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Actions of the WebDriver- element

2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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 ())

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report