playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[BUG] Locators are not being retried on actionability check fail

Open felixschorer opened this issue 3 years ago • 0 comments

Context:

  • Playwright Version: 1.28.1
  • Operating System: Windows
  • Node.js version: v16.16.0
  • Browser: All

Code Snippet

const {chromium, webkit, firefox} = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const context = await browser.newContext();
  const page = await context.newPage();
  
  await page.setContent(`
    <div style='display: none'>first</div>
    <script>
      setTimeout(() => {
        const div = document.createElement('div')
        div.innerText = 'second'
        document.body.appendChild(div)
      }, 1000)
    </script>
  `)

  await page.locator('div').click()
})();

Describe the bug

  • The test page contains a <div /> which is hidden (display: none). It will stay hidden for the remainder of the test.
  • A second <div /> is appended to the page after a delay of 1s . This <div /> is not hidden.
  • The test case tries to find and click a <div /> element.

The hidden <div /> is not actionable. Therefore, I would expect that Playwright would either click the second <div />, or raise an error that more than one element matches the locator. However, that's not what happens:

  1. Playwright resolves the locator to the hidden <div />.
  2. Playwright detects that the div is not actionable.
  3. Playwright waits until the <div /> becomes actionable.
  4. The test case fails due to a timeout as the <div /> will never become actionable.

felixschorer avatar Dec 07 '22 11:12 felixschorer