0

I have an element that looks like this:

 <span class="tab_caption_text">Change&nbsp;Tasks&nbsp;(1)</span>

Of course, the rendered button says "Change Tasks (1)" not "Change Tasks&nbsp(1)"

my problem is that

 driver.findElement(By.xpath("//span[contains(text(), 'Change Tasks')]");

does not work because the space is considered an &nbsp. Now I can't use &nbsp because they will be passing in the tab to search for. there are many with two words. The caller would have to use   instead of space.

Is there any way I can search for this? I suppose the caller of my method could pass something like "Change Tasks" and I could do a replaceAll(" ", " ") but that seems awfully clumsy doesn't it?

p.s., this is with Chromedriver, java 1.8 and selenium

Tony
  • 1,127
  • 1
  • 18
  • 29

1 Answers1

0

Insert a non-breaking space instead of the regular space. This is done with Alt+0160 on Windows, or Alt+Shift+Space on Mac.

Warning that this may make your code tricky to maintain because to the human eye they look the same. If that is unacceptable, you may find this answer to be of further help.