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

[Feature] on('selector' ... #6480

Closed
andrisi opened this issue May 10, 2021 · 2 comments
Closed

[Feature] on('selector' ... #6480

andrisi opened this issue May 10, 2021 · 2 comments

Comments

@andrisi
Copy link

andrisi commented May 10, 2021

We need to automate a site which puts up a dialog box sort of randomly, so not when ou arrive at the site or after a given action but at some point of the usage. It's an ad for a new feature they have. We need to dismiss it to continue, but it's a hassle to check for it all the time plus your auto-wait-before-click feature breaks. Instead we could have an .on(... style event handler that somehow catches dom changes (a selector appearing) between retries of click actions. So you would try to find that button to click but in the meantime let the on ... handler take care of the dialog box. Thanks.

@JoelEinbinder
Copy link
Contributor

It would tricky for us to implement this feature because we wouldn't be able to block on async actions you take when the event fires. But if you are careful with what you do something like this could work.

Warning: Untested code

// do not await this
(async () => {
  let loop = true;
  page.on('close', () => loop = false);
  while (loop) {
    const popup = await page.waitForSelector('.the-popup', {timeout: 0}).catch(() => null);
    if (!popup)
      continue;
    // close the popup
    await popup.click();
  }
})();
// the rest of your test goes here

@JoelEinbinder
Copy link
Contributor

Closing this as it looks like there isn't anything actionable for us here.

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

2 participants