The Light
The Light

Reputation: 27021

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

    <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"]]

Upvotes: 8

Views: 15640

Answers (1)

Serj-Tm
Serj-Tm

Reputation: 16981

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')] 

Upvotes: 24

Related Questions