Python selenium issues when using text that contains a span element

Python selenium issues when using text that contains a span element … here is a solution to the problem.

Python selenium issues when using text that contains a span element

I’m trying to get a span element that contains the text “collections”. I attached a screenshot of the HTML code.
I need to get this element without using the class value and just using the text.
This is something I tried without any luck.
Note that there is a space before the word “colelctions/”

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

It may seem like a simple thing, but somehow it doesn’t work.
Any suggestions?
Thank you very muchenter image description here

Solution

Try the following method:

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

or

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

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

Related Problems and Solutions