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

Locating Elements (2)

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

The fourth method: By CssSelector

It is said that this method is faster than using xpath, and its performance is "much better" than using xpath. Here, I would like to say that if you really want to get to the point, it is really faster than using xpath, but the gap may be only 0.x seconds, but it is true that cssSelector is easier to maintain than xpath. Individuals also like this method and are easier to use. It is recommended that you take a look at the things in css that are very helpful in deepening the understanding of UI (http://www.w3school.com.cn/css/css_syntax_attribute_selector.asp). Here we would also like to mention how to find elements that are easier to use. As for the efficiency of script development and future maintenance and performance, it is important to balance the pros and cons. It is important to reach an agreed specification. It is not awesome to do simple things. It seems to be bullshit.

The basic syntax is

Driver.findElement (By.cssSelector ("*")); here we introduce a plug-in under firefind,firebug, which can help you identify elements with cssSelector. For example, if I want to find the Baidu logo on Baidu's home page, first open the Baidu page with firefox, then press F12 to open firebug, switch to FireFinder, and then enter the CSS attribute to match. If the attribute description is correct, Baidu logo will be highlighted as shown in the figure:

The fifth method: By linkText

This method is more straightforward, that is, to identify elements according to the name of link. For example, the link with a map on the home page of Baidu can be identified by the name "map" of link. The basic syntax is

Driver.findElement (By.linkText ("map"))

The sixth method: By className

This method identifies an element according to its class attribute, but there may be many elements whose class name is the same, so what you get is a collection of elements. The basic syntax is

Driver.findElement (By.className ("* *"))

The seventh method is: By TagName

This method identifies an element based on its TagName. For example, there is an element whose html code is:

You can use this syntax to identify the element:

Driver.findElement (By.tagName ("iframe"))

Of course, there are many other methods, one by one here will not be described, the method is dead, can be used well, can be used well to have value!

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