<root>
// other nodes
<a href="/PatternFramework/Pages/LogOut.aspx?np=/sites/novatestsite/Home.aspx" slick-uniqueid="92">Sign out</a>
</root>
How to write an xpath which returns the a
tag whose href
contains "logout.aspx"?
For instance something like
//a[@href[contains[., "logout.aspx"]]
Identifying by Attribute using Xpath The “@” symbol is used to access attributes. The output shows a single matching node. It is known that utilizing the attribute value with the contain() function and either “Feeling” or “Lucky” will uniquely identify the element.
XPath text() function is a built-in function of the Selenium web driver that locates items based on their text. It aids in the identification of certain text elements as well as the location of those components within a set of text nodes. The elements that need to be found should be in string format.
Case-sensitive:
//a[contains(@href,'logout.aspx')]
Case-insensitive for XPath 2.0:
//a[contains(lower-case(@href),'logout.aspx')]
Case-insensitive for XPath 1.0:
//a[contains(translate(@href, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),'logout.aspx')]
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