Bird
0
0

How can you handle a prompt alert in Selenium Java that requires entering text before accepting it?

hard📝 Application Q9 of 15
Selenium Java - Handling Windows, Frames, and Alerts
How can you handle a prompt alert in Selenium Java that requires entering text before accepting it?
ASwitch to alert, use sendKeys() to enter text, then accept()
BUse dismiss() to enter text and close alert
CUse driver.sendKeys() directly without switching to alert
DUse accept() first, then sendKeys()
Step-by-Step Solution
Solution:
  1. Step 1: Switch to prompt alert

    driver.switchTo().alert() focuses on the prompt alert.
  2. Step 2: Enter text and accept alert

    Use sendKeys() to input text, then accept() to confirm.
  3. Final Answer:

    Switch to alert, use sendKeys() to enter text, then accept() -> Option A
  4. Quick Check:

    sendKeys() then accept() for prompt alerts [OK]
Quick Trick: sendKeys() inputs text, accept() confirms prompt [OK]
Common Mistakes:
MISTAKES
  • Using dismiss() to enter text
  • Not switching to alert before sendKeys()
  • Calling accept() before sendKeys()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes