Bird
0
0

Given the code snippet below, what will be printed?

medium📝 Predict Output Q4 of 15
Selenium Java - Handling Form Elements
Given the code snippet below, what will be printed?
driver.findElement(By.id("autoCompleteInput")).sendKeys("ban");
new WebDriverWait(driver, Duration.ofSeconds(5))
  .until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".suggestions li")));
List options = driver.findElements(By.cssSelector(".suggestions li"));
System.out.println(options.get(0).getText());
ANoSuchElementException at runtime
BAn empty string
CThe first suggestion text starting with 'ban'
DThe input field value 'ban'
Step-by-Step Solution
Solution:
  1. Step 1: Understand code flow

    Text 'ban' is typed, then wait for suggestions list items to appear, then get first suggestion text.
  2. Step 2: Analyze output

    options.get(0).getText() prints the first suggestion starting with 'ban', not input value or empty.
  3. Final Answer:

    The first suggestion text starting with 'ban' -> Option C
  4. Quick Check:

    Printed text = first suggestion [OK]
Quick Trick: Wait for suggestions, then get text from list items [OK]
Common Mistakes:
  • Confusing input field value with suggestion text
  • Not waiting causing NoSuchElementException
  • Assuming empty string output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes