1

I'm using Xpath to select an element based on it's text from a web page, which works as long as the text selector doen't contain spaces.

When the selector does contain spaces, however, it fails.
I have looked at: Locating the node by value containing whitespaces using XPath
and xpath expression to remove whitespace
and how to get the normalize-space() xpath function to work? but that did not work.

A sample of the html that fails:

<tr style="vertical-align:top;">
        <td style="height:15px;"></td>
        <td class="cs9D60B82">Yellow&nbsp;Fees</td>
        <td class="cs9D60B82">Group1</td>
        <td class="cs9D60B82">Yes</td>
        <td class="cs9DB0B82"></td>
        <td class="cs9D60B82">QD&nbsp;1,234.56</td>
</tr>

These work, but could return other nodes starting the same text too:

"//td[starts-with( normalize-space(), 'Yellow')]"  
"//td[starts-with(text(), 'Yellow')]"

These don't work:

 "//td[normalize-space(.) = 'Yellow Fees']"  
 "//td[translate(text(), '&#9;&#xA;&#xD;','') = 'YellowFees']"
 "//td[translate(text(), ' &#9;&#xA;&#xD;','') = 'Yellow&#xA0;Fees']"  
 "//td[translate(text(), '&nbsp;','') = 'YellowFees']"  
 "//td[translate(text(), '&#9;&#xA;&#xD;','') = 'Yellow&nbsp;Fees']"
 "//td[matches( text(), 'Yellow&nbsp;Fees')]"
Community
  • 1
  • 1
callisto
  • 4,921
  • 11
  • 51
  • 92

1 Answers1

1

I found the answer at https://groups.google.com/forum/#!topic/selenium-users/IJP6VKnnEeQ

"//td[starts-with( normalize-space(), 'Yellow\u00A0Fees')]"  

works!

callisto
  • 4,921
  • 11
  • 51
  • 92