Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath to find an element whose attribute contains a text, case-insensitively?

Tags:

xml

xslt

xpath

    <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"]]
like image 838
The Light Avatar asked Mar 07 '12 15:03

The Light


People also ask

How use attribute and contains in XPath?

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.

What is text () in XPath?

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.


1 Answers

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')] 
like image 58
Serj-Tm Avatar answered Oct 22 '22 01:10

Serj-Tm