XPath doesn't detect text with & nbsp; as spaces

7,117 views
Skip to first unread message

Johanan

unread,
Apr 20, 2012, 5:34:24 AM4/20/12
to Selenium Users
I've experienced a problem that is discribed here:

http://groups.google.com/group/selenium-users/browse_thread/thread/65c11c28b44dddee/e997e0df98eb85c8?lnk=gst&q=XPath+unable+to+detect+text+with+%26+nbsp%3B+as+spaces#e997e0df98eb85c8

Exactly, if some text on my site starts with   symbol I cannot
locate it properly.
Using "\u00a0" doesn't help either.

Shaba K

unread,
Apr 20, 2012, 5:59:04 AM4/20/12
to seleniu...@googlegroups.com
Can't you use the contains() function ?? for a string within the text 


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.


Johanan

unread,
Apr 20, 2012, 6:29:52 AM4/20/12
to Selenium Users
In the most cases -yes, I can but still I need use starts-
with(text(), 'filter') when I am testing filtering.

Mark Collin

unread,
Apr 20, 2012, 7:03:15 AM4/20/12
to seleniu...@googlegroups.com
I think you could use some advanced XPath to convert   into a space,
have a look at the following to point you in the right direction:

http://stackoverflow.com/questions/1852571/xpath-function-to-remove-white-sp
ace

--

Johanan

unread,
Apr 20, 2012, 8:23:32 AM4/20/12
to Selenium Users
Thank you for the answer but

//*[starts-with(translate(text(), "\u0160", ''), 'filter')]
//*[starts-with(translate(text(), "\u00a0", ''), 'filter')]
//*[starts-with(translate(text(), "&nbsp", ''), 'filter')]
//*[starts-with(translate(text(), " ", ''), 'filter')]

all these variants do not work. Maybe I am to represent the &nbsp
symbol in &#12 format but I cannot find how to do it.

On 20 апр, 15:03, "Mark Collin" <mark.col...@lazeryattack.com> wrote:
> I think you could use some advanced XPath to convert &nbsp; into a space,
> have a look at the following to point you in the right direction:
>
> http://stackoverflow.com/questions/1852571/xpath-function-to-remove-w...

Shaba K

unread,
Apr 20, 2012, 9:20:31 AM4/20/12
to seleniu...@googlegroups.com
@Mark,

Thanks for sharing that conversation.
That's helpful

Cheers,
Shabana

Johanan

unread,
May 14, 2012, 1:26:24 AM5/14/12
to Selenium Users
We have found the solution:

//*[starts-with(translate(text(), ' ', ''), 'filter')]

this line works! Notice: the 2nd argument in translate() function is
nbsp inserted with Alt+0160
Reply all
Reply to author
Forward
0 new messages