How to write xpath for an element containing '&nbsp' and svg tag in between?

193 Views Asked by At

I am trying to get the xpath of the highlighted element(span) in the below image.

I tried the below options and none of them are working:

 //span[contains(text(),'Database')]
 //span[ends-with(., 'Database')]
 //span[text()='\u00A0\u00A0Database']
 //span[contains(., '\u00A0\u00A0Database')]
2

There are 2 best solutions below

1
undetected Selenium On BEST ANSWER

Given the HTML:

html

The desired text &nbsp;Database is within the <span>.


Solution

To locate the element you can use either of the following locator strategies:

  • Using XPATH and the text Database`:

    //span[contains(., 'Database')]
    
  • Using XPATH and the text &nbsp;Database:

    //span[contains(., '\u00A0Database')]
    

References

You can find a couple of relevant detailed discussion in:

1
Ajeet Verma On

You may try to find the highlighted span tag with its id attribute using XPATH as below:

//span[@id="WD4B-cnt-start"]