Bird
0
0

Consider this code snippet: ```java Alert prompt = driver.switchTo().alert(); prompt.sendKeys("Test"); prompt.dismiss(); String text = driver.findElement(By.id("result")).getText(); System.out.println(text); ``` What will be printed if the prompt alert is dismissed after entering text?

medium📝 Predict Output Q5 of 15
Selenium Java - Handling Windows, Frames, and Alerts
Consider this code snippet: ```java Alert prompt = driver.switchTo().alert(); prompt.sendKeys("Test"); prompt.dismiss(); String text = driver.findElement(By.id("result")).getText(); System.out.println(text); ``` What will be printed if the prompt alert is dismissed after entering text?
ANoSuchElementException
BTest
CAlert text message
DEmpty string or default value
Step-by-Step Solution
Solution:
  1. Step 1: Analyze prompt dismissal effect

    Dismissing a prompt alert cancels input, so entered text is ignored.
  2. Step 2: Check output element text

    The element with id "result" will show empty or default text because input was dismissed.
  3. Final Answer:

    Empty string or default value -> Option D
  4. Quick Check:

    Dismissed prompt = no input saved [OK]
Quick Trick: Dismiss cancels input; accept saves it [OK]
Common Mistakes:
  • Assuming dismiss saves input
  • Expecting alert message instead of result text
  • Confusing accept and dismiss behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes