Is there an xpath way to find a node that has a given attribute whose value contains a given string?
For example I have an xml document and want to find a node where the address
attribute contains the string Downing
, so that I could find the following node:
<person name="blair" address="10 Downing St. London"/>
We can identify elements by partially comparing to its attributes in Selenium with the help of regular expression. In xpath, there is contains () method. It supports partial matching with the value of the attributes. This method comes as useful while dealing with elements having dynamic values in their attributes.
XPath assertion uses XPath expression to select the target node and its values. It compares the result of an XPath expression to an expected value. XPath is an XML query language for selecting nodes from an XML. Step 1 − After clicking Add Assertion, select Assertion Category – Property Content.
select="//*[contains(@address,'Downing')]"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With