Recall & Review
beginner
What is an unexpected alert in Selenium?
An unexpected alert is a popup message (like an alert box) that appears without warning during test execution, which can interrupt the test flow if not handled.
Click to reveal answer
beginner
How do you switch to an alert in Selenium WebDriver using Java?
Use
driver.switchTo().alert() to switch the WebDriver's focus to the alert popup so you can interact with it.Click to reveal answer
beginner
Which method accepts an alert in Selenium WebDriver?
The method
alert.accept() clicks the OK button on the alert, closing it and allowing the test to continue.Click to reveal answer
intermediate
What exception does Selenium throw if an unexpected alert appears?
Selenium throws
UnhandledAlertException when an alert appears unexpectedly and is not handled.Click to reveal answer
intermediate
How can you handle unexpected alerts to avoid test failures?
You can catch
UnhandledAlertException in a try-catch block, switch to the alert, accept or dismiss it, and then continue the test.Click to reveal answer
Which Selenium method switches the driver focus to an alert?
✗ Incorrect
Use driver.switchTo().alert() to access the alert popup.
What happens if an unexpected alert appears and is not handled?
✗ Incorrect
Selenium throws UnhandledAlertException when an alert is not handled.
Which method closes an alert by clicking OK?
✗ Incorrect
alert.accept() clicks OK on the alert popup.
How can you handle an unexpected alert in your test code?
✗ Incorrect
Catching UnhandledAlertException and accepting the alert allows the test to continue.
Which exception is specifically related to unexpected alerts in Selenium?
✗ Incorrect
UnhandledAlertException occurs when an alert is not handled.
Explain how to detect and handle an unexpected alert in Selenium WebDriver using Java.
Think about how to catch exceptions and interact with alerts.
You got /5 concepts.
Describe why handling unexpected alerts is important in automated testing.
Consider what happens if alerts are ignored.
You got /4 concepts.