Bird
0
0

Which approach correctly handles this scenario including waiting and verification?

hard📝 Application Q15 of 15
Selenium Java - Handling Form Elements
You need to write a Selenium Java test to select the suggestion "Cherry" from an auto-complete field with id "fruitInput". The suggestions appear in a ul with class "autocomplete-list" and each suggestion is a li. Which approach correctly handles this scenario including waiting and verification?
ASend keys "Che", use implicit wait, find <code>li</code> with text "Cherry" and click, no assertion needed
BSend keys "Cherry" to input, immediately click first <code>li</code> in <code>ul.autocomplete-list</code>, no wait needed
CSend keys "Che" to input, wait explicitly for visibility of <code>ul.autocomplete-list</code>, find all <code>li</code>, click the one with text "Cherry", then assert input value equals "Cherry"
DClear input, send keys "Ch", use Thread.sleep(5000), click last <code>li</code> in <code>ul.autocomplete-list</code>, assert input value contains "Ch"
Step-by-Step Solution
Solution:
  1. Step 1: Send partial keys and wait explicitly

    Typing "Che" triggers suggestions; explicit wait ensures suggestions are visible before interaction.
  2. Step 2: Find and click correct suggestion, then verify

    Find all li elements, click the one with text "Cherry", then assert input value matches to confirm selection.
  3. Final Answer:

    Send keys "Che" to input, wait explicitly for visibility of ul.autocomplete-list, find all li, click the one with text "Cherry", then assert input value equals "Cherry" -> Option C
  4. Quick Check:

    Explicit wait + correct click + assert input value = Send keys "Che" to input, wait explicitly for visibility of ul.autocomplete-list, find all li, click the one with text "Cherry", then assert input value equals "Cherry" [OK]
Quick Trick: Wait explicitly, click matching text, then verify input value [OK]
Common Mistakes:
  • Not waiting explicitly for suggestions
  • Clicking wrong suggestion or without verification
  • Using Thread.sleep instead of explicit wait

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes