2

In Selenium 2.42.2 and Firefox 29, what is wrong with this XPath expression using regex:

//button[matches(text(),'\s*ABC\s*')]

It gives the following error message:

[Exception... "The expression is not a legal expression."  code: "12" nsresult: "0x805b0033 (SyntaxError)"  location: "<unknown>"]
1
  • Could you please share the reasons to unaccept the answer? May be there is smth to improve? Thanks. Commented Oct 3, 2015 at 2:51

1 Answer 1

1

matches() is a part of xpath 2.0. In terms of xpath support selenium webdriver relies on the browser, which, in your case is Firefox, which, as far as I understand, doesn't support xpath 2.0.

There are plenty of functions in 1.0 that can help you to overcome the issue.

For example, contains():

//button[contains(., 'ABC')]

If the text is at the beginning or end of the string, you can apply starts-with() or ends-with():

//button[starts-with(., 'ABC')]
//button[ends-with(., 'ABC')]

See also this relevant thread:

Sign up to request clarification or add additional context in comments.

2 Comments

@Solver good point, thank you. As far as I understand, Firefox doesn't support 2.0. See also: stackoverflow.com/questions/16658799/….
@Solver also found this issue, that is still open. This is probably a reliable sign of xpath 2.0 being not supported..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.