Bird
0
0

What is the purpose of the dismiss() method when handling alerts in Selenium Java?

easy📝 Conceptual Q1 of 15
Selenium Java - Handling Windows, Frames, and Alerts
What is the purpose of the dismiss() method when handling alerts in Selenium Java?
ATo switch the driver focus back to the main page
BTo close the alert by clicking the Cancel button or equivalent
CTo accept the alert by clicking the OK button
DTo send text input to the alert
Step-by-Step Solution
Solution:
  1. Step 1: Understand the alert types

    Alerts can be accepted or dismissed. Accept means OK, dismiss means Cancel.
  2. Step 2: Know the dismiss() method role

    The dismiss() method clicks the Cancel button or closes the alert without accepting it.
  3. Final Answer:

    To close the alert by clicking the Cancel button or equivalent -> Option B
  4. Quick Check:

    dismiss() = Cancel alert [OK]
Quick Trick: dismiss() cancels alert, accept() confirms it [OK]
Common Mistakes:
  • Confusing dismiss() with accept()
  • Thinking dismiss() closes the browser
  • Assuming dismiss() sends input to alert

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes