<div class="o-text99">
"No "
"messages"
" found"
</div>
I want to identify all the text from the div
, and class attribute value is dynamic, so class attribute value number keep changes.
Note: after "No" there is space and before "found" there is a space.
I’ve tried with below XPath:
//div[contains(@class,'o-text')]/self::div[contains(text(),'No')]/self::div[contains(text(),'messages')]/self::div[contains(text(),'found')]
But, unable to find the results.
Could anybody help me with xpath for identify all the text within the same div
?
2
Answers
This XPath,
will select all
div
elements with aclass
attribute value that starts witho-text
.This XPath,
will select all
div
elements whose space-normalized string-value is'No messages found'
.You can combine the two conditions via
and
,or via a compound predicate:
Note: If it’s actually the text nodes themselves that you wish to select,
append
/text()
to whichever above XPath expresses the types ofdiv
element you’re looking for.If there’s only one such
div
element in the document, and you want itsstring-value
you can place the expression within astring()
function in XPath 1.0, or append/string()
in higher versions of XPath to take the string values of all suchdiv
s in the document.As addition to kjhughes answer
If the div contains these
"
-chars as well you probably could use this XPath: