microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.31k stars 3.62k forks source link

[Question]: witch xpath version playwright supports? #19120

Closed brzssh closed 1 year ago

brzssh commented 1 year ago

Your question

im trying to use xpath 2.0 features such lower-case and matches but getting invalid xpath error

waiting for selector "//*[lower-case(@data-table-column-id)='specInfo.fileName']"
  Failed to execute 'evaluate' on 'Document': The string './/*[lower-case(@data-table-column-id)='specInfo.fileName']' is not a valid XPath expression.
waiting for selector "//*[matches(@data-table-column-id,'specInfo.fileName','i')]"
  Failed to execute 'evaluate' on 'Document': The string './/*[matches(@data-table-column-id,'specInfo.fileName','i')]' is not a valid XPath expression.
angelo-loria commented 1 year ago

I believe this is a browser issue unrelated to Playwright. Most (all?) modern browsers do not support xpath 2.0- https://stackoverflow.com/questions/65271107/why-modern-browser-engines-do-not-support-xpath-2-0

You're better off using a different Locator over xpath with Playwright

pavelfeldman commented 1 year ago

As per above, we use Browser's xpath engine for xpath selectors, but you should use high level locators instead.

DetachHead commented 1 year ago

you can use my playwright-xpath selector engine which supports up to xpath 3.1