Bird
0
0

Which Selenium Java command correctly switches to an alert and accepts it?

easy📝 Conceptual Q2 of 15
Selenium Java - Handling Windows, Frames, and Alerts
Which Selenium Java command correctly switches to an alert and accepts it?
Adriver.switchTo().alert().close();
Bdriver.switchTo().alert().dismiss();
Cdriver.switchTo().alert().accept();
Ddriver.switchTo().alert().sendKeys("OK");
Step-by-Step Solution
Solution:
  1. Step 1: Identify the method to accept alert

    The accept() method confirms the alert, equivalent to clicking OK.
  2. Step 2: Confirm correct syntax

    driver.switchTo().alert() switches focus to alert, then accept() confirms it.
  3. Final Answer:

    driver.switchTo().alert().accept(); -> Option C
  4. Quick Check:

    accept() = OK alert [OK]
Quick Trick: Use accept() to confirm alerts after switching [OK]
Common Mistakes:
  • Using dismiss() instead of accept() to confirm
  • Trying to use close() on alerts
  • Not switching to alert before accept()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes