skip to Main Content
<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


  1. This XPath,

    //div[starts-with(@class,'o-text')]
    

    will select all div elements with a class attribute value that starts with o-text.

    This XPath,

    //div[normalize-space() = 'No messages found']
    

    will select all div elements whose space-normalized string-value is 'No messages found'.

    You can combine the two conditions via and,

    //div[starts-with(@class,'o-text') and normalize-space() = 'No messages found']
    

    or via a compound predicate:

    //div[starts-with(@class,'o-text')][normalize-space() = 'No messages found']
    

    Note: If it’s actually the text nodes themselves that you wish to select,
    append /text() to whichever above XPath expresses the types of div element you’re looking for.

    If there’s only one such div element in the document, and you want its string-value you can place the expression within a string() function in XPath 1.0, or append /string() in higher versions of XPath to take the string values of all such divs in the document.

    Login or Signup to reply.
  2. As addition to kjhughes answer
    If the div contains these "-chars as well you probably could use this XPath:

    //div[starts-with(@class,'o-text')]
         [contains(text() = '"No "']
         [contains(text() = '"messages"']
         [contains(text() = '" found"']
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search