I'm trying to use Selenium RC and WebDriver (separately) to manipulate an HTML page. The source contains something like:
<a href="/logoff"><span>
<span>L</span>
ogoff
</span>
</a>
I want to target the link that contains the text 'Logoff', in such a way that it will still work even if they rework the spans. I'm using XPath since that should work in both WebDriver and Selenium RC. This works in IE but is slightly fragile:
//a[contains(., 'ogoff')]
and this would be more robust but doesn't work:
//a[.='Logoff']
Can you explain why the second doesn't work? In particular, how should .
be interpreted as a string, and how do Selenium and WebDriver do it?
I'm trying to get Selenium to work with Firefox as well, so that will open up another kettle of worms.
There is whitespace (spaces and carriage returns) that are seen by the processor as significant and affecting the computed value of a
.
When you select the value of a
like this *<xsl:value-of select="a"/>*
the result is:
* L
ogoff
*
If you use *<xsl:value-of select="normalize-space(a)"/>*
the result is:
*L ogoff*
If you want to be able to select for "Logoff", you could use normalize-space()
and then wrap it with translate()
to remove the spaces:
//a[translate(normalize-space(), ' ','')='Logoff']
For Selenium you can give it as link="Logoff"
where Logoff is the text in the link.
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