Home > Enterprise >  How to optionally handle a modal with Playwright?
How to optionally handle a modal with Playwright?

Time:11-04

Sometimes there is a modal window that pops up. I have this try catch to handle it and it works in headless mode. However, when I'm in VSCode, it stops when the error is thrown.

await test.step('Optionally click continue', async () => {
    try {
        page.getByRole('cell', { name: 'Continue' }).click({ timeout: 10000 });
    } catch (error) {

    }
});

Error Screenshot

Is there a playwright preferred way to handle this that doesn't throw an exception? The playwright extension stops on exceptions to help debug. In this case, I would prefer a way to optionally handle a button without an exception being thrown.

CodePudding user response:

You can use:

if page.isVisible('role=cell[name="Continue"i]') {
//Whatever
}
  • Related