Bird
0
0

Identify the error in this Selenium Java code for entering text in a prompt alert:

medium📝 Debug Q14 of 15
Selenium Java - Handling Windows, Frames, and Alerts
Identify the error in this Selenium Java code for entering text in a prompt alert:
Alert alert = driver.switchTo().alert();
alert.sendKeys("test");
alert.dismiss();
Aalert variable should be WebElement
BMissing driver initialization
CsendKeys() cannot be used on alerts
DUsing dismiss() instead of accept() after sendKeys()
Step-by-Step Solution
Solution:
  1. Step 1: Check alert method usage

    sendKeys() inputs text, but dismiss() cancels the prompt, ignoring input.
  2. Step 2: Correct method to confirm input

    accept() should be used to confirm and submit the entered text.
  3. Final Answer:

    Using dismiss() instead of accept() after sendKeys() -> Option D
  4. Quick Check:

    Use accept() to confirm prompt input [OK]
Quick Trick: Use accept() after sendKeys(), not dismiss() [OK]
Common Mistakes:
  • Calling dismiss() cancels input silently
  • Confusing alert with WebElement
  • Forgetting to switch to alert before sendKeys()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes