1

I'm looking for some hint how to use xpath "ends-with" expression. I've got such element to find:

<div class="osaiowrhg29875n345" id="react-select-4-listbox">

Previous selector I used was:

//div[starts-with(@id,'react-select-4')]

and its working properly but there are more of such elements and the number is changing so I wanted to catch only the ending of this ID using

//div[ends-with(@id,'listbox')]

Why its not working for me?

Prophet
  • 32,350
  • 22
  • 54
  • 79

1 Answers1

2

The issue is: starts-with is available in XPath 1.0 while ends-with was only introduced by XPath 2.0 .
Selenium supports XPath 1.0 only.
That's why ends-with will not work with Selenium.
But you still can use contains with Selenium.
So //div[ends-with(@id,'listbox')] can be changed by

"//div[contains(@id,'listbox')]"
Prophet
  • 32,350
  • 22
  • 54
  • 79