I have been doing Playwright testing for some time on my company's site, and mostly it's gone all right. But we subscribe to Intercom, and it seems to pop up almost randomly, obscuring stuff I want to test. I've tried several ways, and this one seems to work:
this.page.on('frameattached', async (frame) => {
await new Promise((resolve) => setTimeout(resolve, 500));
try {
const dismiss = await frame.waitForSelector('div[aria-label="Dismiss"]');
if (dismiss) {
dismiss.click({ timeout: 2000 });
}
} catch (_) {
return Promise.resolve();
}
return Promise.resolve();
});
It's pretty clunky, though. I dislike using locators when it seems like ElementHandle would be the way to go, but I cannot figure out the syntax for it. It's easy enough to get the ElementHandle with frame.$(), but then I can't just do a .click() on the result.
Any clues on how to do this without the tedious timeout and try-catch?