Bird
0
0

What will be the output of the following code snippet if the prompt alert is displayed with message "Enter name" and user inputs "Alice"?

medium📝 Predict Output Q4 of 15
Selenium Java - Handling Windows, Frames, and Alerts
What will be the output of the following code snippet if the prompt alert is displayed with message "Enter name" and user inputs "Alice"? ```java Alert prompt = driver.switchTo().alert(); prompt.sendKeys("Alice"); prompt.accept(); String result = driver.findElement(By.id("output")).getText(); System.out.println(result); ```
AEnter name
BAlice
Cnull
DNoSuchElementException
Step-by-Step Solution
Solution:
  1. Step 1: Understand prompt alert input and acceptance

    The code sends "Alice" to the prompt alert and accepts it, submitting the input.
  2. Step 2: Check the output element text

    Assuming the page updates element with id "output" to show the entered text, getText() returns "Alice".
  3. Final Answer:

    Alice -> Option B
  4. Quick Check:

    Prompt input accepted = output shows input text [OK]
Quick Trick: Accepted prompt input usually updates page text [OK]
Common Mistakes:
  • Expecting alert message instead of input text
  • Assuming element is missing causing exception
  • Confusing prompt text with output element text

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes