I'm trying to find the following button in Selenium (Java):
<bdi id="__label1-__xmlview1--Table-Popup-bdi">My But­ton</bdi>
innerHTML & innerText of the element return My Button
only. Outer html returns vale without hyphens as well:
<bdi id="__label1-__xmlview1--Table-Popup-bdi">My Button</bdi>
None of the answers for similar questions work for me, e.g.:
//bdi[translate(., '­', '') = 'My Button']
//bdi[translate(., '\u00AD', '') = 'My Button']
//bdi[contains(@id, 'Table') and contains(@id, 'Popup') and contains(translate(text(), '\u00AD', ''), 'My Button')]
//bdi[contains(@id, 'Table') and contains(@id, 'Popup') and contains(translate(., '\u00AD', ''), 'My Button')]
//bdi[contains(@id, 'Table') and contains(@id, 'Popup') and translate(text(), '\u00AD', '')='My Button']
//bdi[contains(@id, 'Table') and contains(@id, 'Popup') and translate(., '\u00AD', '')='My Button']
//bdi[translate(., '-', '') = 'My Button']
all of these are unable to find the button. If I provide a name of a button that does not have soft hyphens, the xpaths work alright (so I know it's a problem with the hyphens). replace()
does not work, as I'm using Xpath 1.0
. Using starts-with
and ends-with
or contains
is not helpful in this case, as this issue occurs in several button names and I'm looking for a more universal solution than hardcoding each name break separately.
I only have DOM to work with, my team doesn't have any contact with developers so any help is appreciated. I'd love to understand what's happening here.
Edited: Please see VGR's comment for solution that worked for me.
this comment contained the solution - using string()
instead of text()
or .
Read more: Difference between text() and string()
Does //bdi[translate(string(), '\u00AD', '') = 'My Button'] work?
– VGR Commented Oct 21 at 14:14