2
votes

I'm trying to grab a span element that has text " collections". I attach a screenshot of the HTML code. I need to get this element not using the class values but just the text. This is what I tried without any luck. Notice that there's an empty space before the word 'colelctions/'

//*[contains(text(),' collections')]

It seems a pretty simple thing to do but somehow it doesn't work. Any suggestions? Many thanksenter image description here

2

2 Answers

2
votes

Try to use below instead:

//*[contains(.,' collections')]

or

//*[contains(text()[2],' collections')]

Here is a post about difference between . and text()

0
votes

To grab the element with text as collections as the element is an Angular element you have to induce WebDriverWait and you can use the following solution:

element = driver.find_element_by_xpath("//span[normalize-space()='collections']")