Bird
0
0

Which Selenium Java code snippet correctly waits for the auto-complete suggestion list to appear before selecting an option?

easy📝 Syntax Q12 of 15
Selenium Java - Handling Form Elements
Which Selenium Java code snippet correctly waits for the auto-complete suggestion list to appear before selecting an option?
Anew WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.visibilityOfElementLocated(By.id("suggestions")));
Bdriver.findElement(By.id("suggestions")).click();
CThread.sleep(10000); driver.findElement(By.id("suggestions")).click();
Ddriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); driver.findElement(By.id("suggestions")).click();
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct wait usage

    Explicit wait with WebDriverWait and ExpectedConditions waits for element visibility properly.
  2. Step 2: Compare with other options

    driver.findElement(By.id("suggestions")).click(); clicks without waiting, C uses Thread.sleep which is not best practice, D uses implicit wait which is less reliable for dynamic elements.
  3. Final Answer:

    new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.visibilityOfElementLocated(By.id("suggestions"))); -> Option A
  4. Quick Check:

    Explicit wait for visibility = new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.visibilityOfElementLocated(By.id("suggestions"))); [OK]
Quick Trick: Use explicit waits with ExpectedConditions for dynamic elements [OK]
Common Mistakes:
  • Using Thread.sleep instead of explicit wait
  • Relying only on implicit waits
  • Clicking before element is visible

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes