Bird
0
0

What does the accept() method do when called on a JavaScript alert in Selenium?

easy📝 Conceptual Q11 of 15
Selenium Java - Handling Windows, Frames, and Alerts
What does the accept() method do when called on a JavaScript alert in Selenium?
AClicks the OK button on the alert
BClicks the Cancel button on the alert
CCloses the browser window
DThrows an exception without interacting
Step-by-Step Solution
Solution:
  1. Step 1: Understand alert interaction methods

    The accept() method is used to click the OK button on an alert popup.
  2. Step 2: Differentiate from dismiss()

    The dismiss() method clicks Cancel, so accept() must click OK.
  3. Final Answer:

    Clicks the OK button on the alert -> Option A
  4. Quick Check:

    accept() = OK click [OK]
Quick Trick: accept() clicks OK, dismiss() clicks Cancel [OK]
Common Mistakes:
MISTAKES
  • Confusing accept() with dismiss()
  • Thinking accept() closes the browser
  • Assuming accept() throws an exception

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes