0

For example, I have an element

<div>TestMessage<div>

How do I get this element by 'testmessage' text?

Next options don't work:

//div[contains(., 'testmessage')]
//div[matches(text(),'testmessage','i')]
//div[lower-case(text())='testmessage'] 
//div[lower-case(.)='testmessage']
Kirill
  • 1,530
  • 5
  • 24
  • 48
  • I googled, none of them works. Even translate. – Kirill Nov 05 '14 at 17:49
  • My bad, I used `//text([contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'test')]` instead of `/html/body//text()[contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'test')]`. Thank you. – Kirill Nov 05 '14 at 17:56
  • For the record, `matches()` and `lower-case()` require XPath 2.0. Failure with those and success with `translate()` indicate that your XPath library does not support XPath 2.0. Answers for both are included in [**case insensitive xpath contains() possible?**](http://stackoverflow.com/questions/8474031/case-insensitive-xpath-contains-possible), so I recommend this be closed a duplicate. Thanks. – kjhughes Nov 05 '14 at 18:18

1 Answers1

1

Works perfectly:

/html/body//text()[contains(translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'test')]

Source

Community
  • 1
  • 1
Kirill
  • 1,530
  • 5
  • 24
  • 48