TESTEVERYTHING

Monday 1 August 2016

XPath unable to find text with   or   using webdriver /

Hi,

Some times we face issues to create XPath of  WebElement which have space in starting of it and then we check the element html source where we found   or &nbsp is added before the element text while it display as space on UI. Normally we create the XPath to identify this element by adding space in the starting of it but his will not identify the element. There are another workaround to identify this element by contains text method. But if we have to identify the element with exact text having starting space or ending space  then we can use following way to do this.

lets see this example

<div class="myclass">
<label>AgendaShowCapacity&nbsp;</label>
</div>

OR

<div class="myclass">
<label>
&nbspAgendaShowCapacity</label>
</div>

Following XPath will not work for this

//label[text()='AgendaShowCapacity&nbsp;'] doesn't work


Here we have to use following text to identify the element

&nbsp; \u00a0

&nbsp \u0160


So XPath will be like this


//label[text()='AgendaShowCapacity\u00a0']


//label[text()='
\u0160AgendaShowCapacity']

Which one is right ?

Translate







Tweet