XPath unable to detect text with & nbsp; as spaces

1,017 views
Skip to first unread message

Mark

unread,
Feb 29, 2008, 5:48:26 PM2/29/08
to selenium-users...@googlegroups.com
Hi All,

My XPath expressions aren't matching text in cases where the text contains spaces created using  . Take this example :

{code:html}<node>sample& nbsp;text</node>{code}

the Xpath expression "//node[ . = 'sample text']" won't match this node, "//node[ . = 'sample& nbsp;text']" also doesn' work. If the   in the source is changed to a normal white space everything works just fine. I've been testing this with firefox, I get the same results even when using the "XPather" firefox extension for the Dom Inspector. As a side note i find that thing extremely handy for building Xpath expressions, definitely recommend it :)

I'm really hoping there is some kind of html-decode() function that can be used, or some other way of escaping things so it works. I've done a lot of searching and come up with nothing except this forum post :

http://osdir.com/ml/web.selenium.devel/2005-12/msg00040.html

Any help would be much appreciated!

Thanks,
Mark

Edited by: iceman153 on Feb 29, 2008 4:52 PM

Discovered the Edit feature and fixed the nbsp's

ΓΙΑΝΝΗΣ ΠΑΠΑΔΑΚΗΣ

unread,
May 22, 2013, 7:12:34 AM5/22/13
to seleniu...@googlegroups.com, selenium-users...@googlegroups.com, clear...@openqa.org, mki...@gmail.com
I have the same problem and tried various solutions but none worked for me:

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

The only thing that worked was to replace the text with text.replaceAll(" ","\u00A0")

Regards,
Giannis

David

unread,
May 22, 2013, 5:53:25 PM5/22/13
to seleniu...@googlegroups.com, selenium-users...@googlegroups.com, clear...@openqa.org, mki...@gmail.com
The only thing that worked was to replace the text with text.replaceAll(" ","\u00A0")

You mean using Java's string.replaceAll() method? So use your language's relevant string replace method to do same. 
Reply all
Reply to author
Forward
0 new messages