Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What does contains(.,'substring') mean in XPath and what's its equivalent in CSS?

Able to locate all div elements in UI page using this XPATH locator : //div[contains(.,'')] irrespective of the text inside them. What does .,'' mean ?

Consider below example:

XPath to specifically select div with text – 'Apple' would be //div[contains(.,'Apple')].

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What is its CSS equivalent ?

<div>
<span> Apple </span>
</div>

>Solution :

//div[contains(.,'Apple')]

  1. //div means to select all div elements in the document.
  2. //div[ predicate ] means to filter those per the given predicate.
  3. contains( str, substr ) means to return true iff str contains the substring, substr.
  4. . is the context node. (See Current node vs. Context node in XSLT/XPath?) Within the predicate of your XPath, it will be a div element. When passed as a function parameter with type string, it will be converted to the string value of the node.
  5. The string-value of an element is equal to the concatenation of the string values of its children elements.

Therefore, your XPath returns all div elements in the document whose string value contains the 'Apple' substring.

There is no CSS equivalent.

See also

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading