Bird
0
0

You want to automate a test where a prompt alert asks for a username, and the page displays "Welcome, [username]!" after accepting. Which sequence correctly handles this scenario?

hard📝 Application Q8 of 15
Selenium Java - Handling Windows, Frames, and Alerts
You want to automate a test where a prompt alert asks for a username, and the page displays "Welcome, [username]!" after accepting. Which sequence correctly handles this scenario?
ASendKeys username directly to page element, accept alert, verify message
BSwitch to alert, sendKeys username, accept alert, verify welcome message
CAccept alert first, then sendKeys username, verify message
DDismiss alert, then sendKeys username, verify message
Step-by-Step Solution
Solution:
  1. Step 1: Handle prompt alert input correctly

    First switch to alert, then sendKeys to input username, then accept to submit.
  2. Step 2: Verify page updates welcome message

    After accepting, check the page text to confirm "Welcome, [username]!" appears.
  3. Final Answer:

    Switch to alert, sendKeys username, accept alert, verify welcome message -> Option B
  4. Quick Check:

    Correct prompt handling = sendKeys + accept + verify [OK]
Quick Trick: Send keys then accept prompt before verifying page text [OK]
Common Mistakes:
  • Sending keys before switching to alert
  • Accepting alert before sending keys
  • Dismissing alert instead of accepting

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes