I have one question about xpath. There is td like this in chrome:
<td class="dataCol col02">
"Hello world(notes:there is$)nbsp;"
<a href="xxxx">[View Hierarchy]</a>
</td>
but when I inspect the same element in Firefox it doesn't have $nbsp and double quotes;
<td class="dataCol col02">
Hello world
<a href="xxxx">[View Hierarchy]</a>
</td>
I used FireFinder and use the xpath:
//td[text()='Hello world']
, it can locate that element.
but when I use selenium api 2.24, it couldn't find that element.
by.xpath("//td[text()='Hello world']")
Do you have any idea of that? Thanks!
Try with normalize-space()
which trims leading and trailing whitespace characters:
//td[normalize-space(text())='Hello world']
Edit following the different comments:
here's an XPath expression that's probably better suited in the general case:
//td[starts-with(normalize-space(.), 'Hello world')]
meaning it matches <td>
nodes if the concatenated string content of the whole <td>
, less leading and trailing whitespace, starts with "Hello world"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With