Have you ever thought of the difference between CSS positioning and XPath?

Source: Internet
Author: User
Tags xpath

I understand that CSS selection is as specific as you can describe the shape of an element, including his: tags, classes, IDs, and the combination of these, the goal is to determine the element's unique coordinates as much as possible to facilitate selection. XPath is based on the path of the element to determine the coordinates.

For example, the description of Shanghai, with CSS may be that it is a municipality (class), in the lower reaches of the Yangtze River (label), is China's largest city (ID), populous, economically developed (other labels)

The XPath is: it is longitude 121°.4′, north latitude 31°.2′ City (absolute path) or south of Jiangsu, Zhejiang Province, east of Suzhou, Yangtze River estuary (relative path)

CSS selection is based on the data style of the page, there are tag selection, class selection, id selection, or their orthogonal set, there is no other auxiliary elements.

XPath is a path expression, and all elements and content can be part of a path. The two positioning methods are basically consistent, but XPath is significantly more powerful, but XPath is more complex to write, and CSS is easier to write.

Have done some experiments, with CSS sometimes choose a bunch of data, with XPath is the only, more useful tools such as Firefox plug-in view XPath, can be more accurate direct selection

In fact, sometimes encounter two elements of the label, class, id exactly the same situation, this time with CSS is more difficult to do, although this situation is very few. However, the XPath absolute path can be resolved

Have you ever thought of the difference between CSS positioning and XPath?

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.