简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM