4
<td>
 <a>SAMPLE</a>
 <div>
  <small>Phase:
         Planning >>
  <a>Performance</a>
  </small>
 </div>         
</td>

I'm trying to locate the element with "Phase: Planning >> Performance" text on the above but to no avail.

Tried using :

//*[text()[contains(normalize-space(.),'Phase: Planning >> Performance')]]
kjhughes
  • 89,675
  • 16
  • 141
  • 199
rai
  • 43
  • 3

4 Answers4

3

None of the currently existing other three answers will do exactly what you ask.

Here are some XPath expressions that will:

  • You can select the small elements whose normalized string value is Phase: Planning >> Performance via this XPath:

    //small[normalize-space() = 'Phase: Planning >> Performance']
    
  • You can select all elements, regardless of name whose normalized string values equals the targeted string:

    //*[normalize-space() = 'Phase: Planning >> Performance']
    

    but this will select not only small but also div because both have a string value equal to Phase: Planning >> Performance.

  • You can select only the lowest element in the hierarchy, regardless of name whose normalized string values equals the targeted string:

    //*[         normalize-space() = 'Phase: Planning >> Performance' and 
        not(.//*[normalize-space() = 'Phase: Planning >> Performance'])]
    

It is important to realize that XPath text() = is different than XPath . =.

Community
  • 1
  • 1
kjhughes
  • 89,675
  • 16
  • 141
  • 199
0

Try Below:-

//small[contains(.,'Phase:')]

Hope it will help you :)

Shubham Jain
  • 13,158
  • 9
  • 60
  • 102
0
<span>Planning &gt;&gt;</span>

try this code

user25775
  • 65
  • 1
  • 10
0

The text Phase: Planning >> and Performance belongs to two different elements.

To locate Phase: Planning >> element you can use

//small[contains(text(),'Phase:')]

And to locate the Performance element

//a[contains(text(),'Performance')]

Note that that printing the first element will give you the text of both elements Phase: Planning >> Performance.

Guy
  • 34,831
  • 9
  • 31
  • 66