arrow-left Back to topicQuizDialogsCheck yourself1.Your app shows a window.confirm() dialog when clicking Delete. The test calls .click() but the order is never deleted. What's the most likely cause?The locator for the Delete button is wrongPlaywright auto-dismisses confirm() with Cancel, so the code receives false and skips deletionThe test needs await page.waitForTimeout(2000) before the click2.Why must you register the page 'dialog' event handler BEFORE the action that triggers the dialog?Playwright requires all event handlers to be registered at test startIf the dialog appears before the handler is attached, Playwright auto-dismisses it and your handler never runsThe browser blocks the action until a dialog handler is registeredDialog handlers can only be registered once per test3.What does dialog.message() return?The type of dialog: 'alert', 'confirm', or 'prompt'The text shown inside the dialog — the message passed to alert(), confirm(), or prompt()The value the user typed into a prompt dialogThe HTML content of the dialog element4.Your app shows a prompt() dialog asking users to type a name. How do you simulate the user typing 'Test Order' and clicking OK?page.on('dialog', dialog => dialog.accept()) — accept fills the default valuepage.on('dialog', async dialog => await dialog.accept('Test Order'))page.on('dialog', dialog => dialog.fill('Test Order').accept())page.keyboard.type('Test Order') then dialog.accept()5.What is the difference between dialog.accept() and dialog.dismiss()?accept() closes the dialog; dismiss() leaves it openaccept() clicks OK/Yes (confirm returns true, prompt returns the value); dismiss() clicks Cancel (confirm returns false, prompt returns null)They are identical for alert dialogs but different for confirmdismiss() only works for beforeunload dialogs6.What happens if a dialog appears during a test and no 'dialog' event handler is registered?The test throws an error immediatelyPlaywright auto-dismisses the dialog: OK for alert, Cancel for confirm and promptThe dialog stays open and the test hangs waiting for user inputThe browser screenshot captures the dialog and the test continues7.How do you verify the text of an alert dialog message inside a dialog handler?page.on('dialog', dialog => expect(dialog.text()).toBe('5 orders pending'))Capture dialog.message() inside the handler into a variable, then assert it after the triggering actionpage.waitForDialog().then(d => expect(d.message()).toBe(...))Use page.screenshot() to capture the dialog text visually8.You want to handle only the next dialog that appears, not all future ones. What do you use?page.on('dialog', handler) then page.off('dialog', handler) after the actionpage.once('dialog', handler) — fires for the next dialog only and auto-removes itselfpage.waitForEvent('dialog') then call handler on the resultSet a flag inside the handler to skip subsequent callsSubmit answersarrow-left PreviousFramesDownloadsNext arrow-right