1

I have some HTML code:

<div>
  <div id="order-1"></div>
  <div id="order-2"></div>
</div>

I want to find all DIVs with IDs 'order'. In Ruby I try

divs = driver.find_elements :xpath, '//div[matches(@id, "order-[0-9]")]'

But Selenium gives a error

Selenium::WebDriver::Error::InvalidSelectorError: invalid selector: Unable to locate an element with the xpath expression //div[matches(@id, "order-[0-9]")] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//div[matches(@id, "order-[0-9]")]' is not a valid XPath expression.

Why?

Sergey Blohin
  • 600
  • 1
  • 4
  • 31
  • 1
    The `matches` function was introduced in XPath 2.0 in 2007 but unfortunately many XPath implementations remain XPath 1.0 implementations without support for that function and others introduced in XPath 2.0. – Martin Honnen Feb 08 '15 at 10:21
  • @MartinHonnen, thanx! Selenium used XPath 1.0. I try //div[starts-with(@id, 'order-')]. It's work! – Sergey Blohin Feb 08 '15 at 10:29

1 Answers1

0

You can use starts-with, though that does not check for a number at the end of the id:

//div[starts-with(@id,"order-")]
Kobi
  • 135,331
  • 41
  • 252
  • 292