Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] page.waitForEvent('dialog') is not working #4737

Closed
qtpsudhakar opened this issue Dec 16, 2020 · 5 comments
Closed

[BUG] page.waitForEvent('dialog') is not working #4737

qtpsudhakar opened this issue Dec 16, 2020 · 5 comments

Comments

@qtpsudhakar
Copy link

Context:

  • Playwright Version: 1.6
  • Operating System: windows
  • Node.js version: 15.x
  • Browser: chromium

Code Snippet

const [dialog] = await Promise.all([
    page.waitForEvent('dialog'),
    page.click("id=searchBtn")
]);
let msg = dialog.message();
if (msg==="from place required") {
    console.log("Validation successful");
}

Describe the bug

I have multiple alerts in page in different situations. I tried with below code. It successfully clicked on searchBtn element and displayed alert. After that I get an error stating that searchBtn is failed. But it clicks and alert is displayed.

page.click: Timeout 30000ms exceeded.
=========================== logs ===========================
waiting for selector "id=searchBtn"
selector resolved to visible <input type="button" id="searchBtn" title="Search" name…/>
=========================== logs ===========================

After that I have used below code and it works on clicking in button.

page.on('dialog', async dialog => {
if (dialog.message() === "from place required") {
console.log("Validation successful");
}
await dialog.accept();
});

What is the problem in First code snippet? Why is that not working? Why is it giving incorrect log info even after clicking on button? What is the purpose of page.waitForEvent('dialog')?

@pavelfeldman
Copy link
Member

const [dialog] = await Promise.all([
    page.waitForEvent('dialog'),
    page.click("id=searchBtn")  // <-- this never resolves, because dialog is hanging.
]);
let msg = dialog.message(); // <-- so you don't event get here

@ducalpha
Copy link

I encountered the same problem with playwright-python. I filed an issue there.

@VincentDondain
Copy link

Hi, I think I'm experiencing a similar issue with:

const [newPage] = await Promise.all([
      context.waitForEvent('page'),
      page.click('css=[aria-label*="Remote port 127.0.0.1:7000 forwarded to"] >> css=[title="Open in Browser"]'),
    ])

Which is giving me:

 TimeoutError: Timeout while waiting for event "page"
    Note: use DEBUG=pw:api environment variable and rerun to capture Playwright logs.

      at node_modules/playwright/lib/client/waiter.js:40:51
      at Waiter.waitForPromise (node_modules/playwright/lib/client/waiter.js:48:28)
      at ChromiumBrowserContext.waitForEvent (node_modules/playwright/lib/client/browserContext.js:190:24)
          at async Promise.all (index 0)

In this case, it looks like the click in the Promise is resolved because the navigation happens but we still timeout and the rest of the code isn't executed.

See logs:

pw:api => page.click started +0ms
  pw:api waiting for selector "css=[aria-label*="Remote port 127.0.0.1:7000 forwarded to"] >> css=[title="Open in Browser"]" +1ms
  pw:api   selector resolved to hidden <a tabindex="0" role="button" title="Open in Browse…></a> +88ms
  pw:api attempting click action +4ms
  pw:api   waiting for element to be visible, enabled and not moving +0ms
  pw:api     element is not visible - waiting... +2ms
  pw:api     element is moving - waiting... +24s
  pw:api   element is visible, enabled and does not move +25ms
  pw:api   scrolling into view if needed +0ms
  pw:api   done scrolling +1ms
  pw:api   checking that element receives pointer events at (1070.35,622.32) +2ms
  pw:api   element does receive pointer events +6ms
  pw:api   performing click action +0ms
  pw:api   click action done +5ms
  pw:api   waiting for scheduled navigations to finish +0ms
  pw:api   navigations have finished +3ms
  pw:api <= page.click succeeded +4ms
  pw:api   navigated to "about:blank" +149ms
  pw:api   navigated to "https://github.com/codespaces/auth/2e95debd-841f-45bd-a1a4-38271f92e397?port=7000&cid=491139482aa08679ed1e02b0e2e48b00" +1s
  pw:api   navigated to "https://auth.apps.codespaces.githubusercontent.com/authenticate-codespace/2e95debd-841f-45bd-a1a4-38271f92e397?cid=491139482aa08679ed1e02b0e2e48b00&port=7000" +531ms
  pw:api   "domcontentloaded" event fired +37ms
  pw:api   "load" event fired +1ms
  pw:api   navigated to "https://2e95debd-841f-45bd-a1a4-38271f92e397-7000.apps.codespaces.githubusercontent.com/" +226ms
  pw:api   "load" event fired +7ms
  pw:api   "domcontentloaded" event fired +4ms
  pw:api   "networkidle" event fired +497ms

Environment:

Playwright 1.7.1
System:
    OS: macOS 11.1
    Memory: 23.84 GB / 64.00 GB
  Binaries:
    Node: 14.8.0 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.9 - /usr/local/bin/npm
  Languages:
    Bash: 3.2.57 - /bin/bash

@dgozman
Copy link
Contributor

dgozman commented Jan 7, 2021

@VincentDondain Do you have a dialog (like an alert box) on your page? Try putting the following at the start of your script, does it help?

page.on('dialog', dialog => dialog.dismiss());

@pavelfeldman
Copy link
Member

Please reopen if still an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants