Playwright: [BUG] Xpath starting with `.` not picked up by xpath heuristic

Created on 12 May 2020  路  2Comments  路  Source: microsoft/playwright

Context:

  • Playwright Version: 1.0.1
  • Operating System: All
  • Node version: 12.x
  • Browser:All

Code Snippet

Help us help you! Put down a short code snippet that illustrates your bug and
that we can run and debug locally. For example:

    const browser = await playwright.chromium.launch({ headless: false})
    const context = await browser.newContext({ viewport: null })
    const page = await context.newPage()

    await page.goto('chrome://downloads')

    const element = await page.waitForSelector('.//div', {timeout: 3000})

Describe the bug
It tries to use the css locator strategy instead.
I'm guessing this might be a hard problem to solve given the semantics.

image

As you can see this is a valid xpath
image

Most helpful comment

@Georgegriff Even though we can hot-fix this particular case, the general problem of differentiating between xpath and css is not an easy one and looks like a slippery slope to me. So we'd rather be conservative and stick with a simple-and-clear rule we have today:

only those selectors that start with // are treated as xpath.

Honestly, it wasn't that easy to find the rules for our selectors in the docs - I've updated docs to have clear references (#2213). Hopefully it'll make life easier.

All 2 comments

@Georgegriff Even though we can hot-fix this particular case, the general problem of differentiating between xpath and css is not an easy one and looks like a slippery slope to me. So we'd rather be conservative and stick with a simple-and-clear rule we have today:

only those selectors that start with // are treated as xpath.

Honestly, it wasn't that easy to find the rules for our selectors in the docs - I've updated docs to have clear references (#2213). Hopefully it'll make life easier.

That's fair, in the framework this came from (CodeceptJS) they have a different heuristic for figuring out xpath so can fix over there rather than here for our user cases thanks for responding

Was this page helpful?
0 / 5 - 0 ratings