Bird
0
0

What is wrong with this code snippet that tries to enter text into a prompt alert?

medium📝 Debug Q7 of 15
Selenium Java - Handling Windows, Frames, and Alerts
What is wrong with this code snippet that tries to enter text into a prompt alert? ```java Alert prompt = driver.switchTo().alert(); prompt.sendKeys("Test"); prompt.accept(); prompt.sendKeys("More"); ```
Aaccept() should be called before sendKeys()
BsendKeys method does not exist
CCannot send keys after alert is accepted
Ddriver.switchTo().alert() returns null
Step-by-Step Solution
Solution:
  1. Step 1: Understand alert lifecycle

    Once accept() is called, the alert is closed and cannot receive further input.
  2. Step 2: Identify invalid method call

    Calling sendKeys() after accept() causes an error because alert no longer exists.
  3. Final Answer:

    Cannot send keys after alert is accepted -> Option C
  4. Quick Check:

    Alert closed after accept() [OK]
Quick Trick: Send keys before accept; alert closes after accept() [OK]
Common Mistakes:
  • Trying to interact with alert after accept()
  • Misunderstanding alert lifecycle
  • Assuming sendKeys() can be called multiple times

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes