Bird
0
0

What is wrong with this code?

medium📝 Debug Q7 of 15
Selenium Java - Handling Windows, Frames, and Alerts
What is wrong with this code?
Alert alert = driver.switchTo().alert();
alert.dismiss();
alert.accept();
Adismiss() should be called after accept()
BCalling accept() after dismiss() on the same alert causes exception
CNo need to assign alert to a variable
DSyntax error in alert assignment
Step-by-Step Solution
Solution:
  1. Step 1: Understand alert state after dismiss()

    dismiss() closes the alert, so alert no longer exists.
  2. Step 2: Calling accept() after dismiss()

    Calling accept() on closed alert throws NoAlertPresentException.
  3. Final Answer:

    Calling accept() after dismiss() on the same alert causes exception -> Option B
  4. Quick Check:

    Alert closed after dismiss(), can't accept() [OK]
Quick Trick: Alert closed after dismiss(), can't accept() again [OK]
Common Mistakes:
  • Calling accept() after dismiss() on same alert
  • Assuming alert stays open after dismiss()
  • Ignoring exception possibility

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes