Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath text() expression - what to specify in text() if it contains newline

Tags:

xpath

The text is as:

text1
text2

How can I specify this text in xpath. I tried:

.//*[@id='someid']//h6[text() ='text1text2]

.//*[@id='someid']//h6[text() ='text1\ntext2]

.//*[@id='someid']//h6[text() ='text1 text2]

None of them worked

like image 387
Shruti Singh Avatar asked May 28 '15 09:05

Shruti Singh


1 Answers

Use .//*[@id='someid']//h6[. = 'text1
text2']. This assumes you are writing the path inside of XSLT or XForms where you can use 
 to escape a new line character. If you are not using XSLT you might want to tell us in which host language (e.g. PHP, C#, Java) you use XPath.

like image 171
Martin Honnen Avatar answered Oct 11 '22 00:10

Martin Honnen