Bird
0
0

Given this Base Page method, what will be the output if the element is not found within 5 seconds?

medium📝 Predict Output Q4 of 15
Selenium Java - Page Object Model
Given this Base Page method, what will be the output if the element is not found within 5 seconds?
public void clickWhenVisible(By locator) {
  new WebDriverWait(driver, Duration.ofSeconds(5))
    .until(ExpectedConditions.visibilityOfElementLocated(locator))
    .click();
}
AThrows TimeoutException after 5 seconds
BClicks immediately without waiting
CReturns silently without clicking
DThrows NoSuchElementException immediately
Step-by-Step Solution
Solution:
  1. Step 1: Understand WebDriverWait behavior

    WebDriverWait waits up to the specified time for the condition to be true.
  2. Step 2: Identify behavior when element not visible

    If the element is not visible within 5 seconds, a TimeoutException is thrown.
  3. Final Answer:

    Throws TimeoutException after 5 seconds -> Option A
  4. Quick Check:

    Wait timeout = TimeoutException [OK]
Quick Trick: Wait throws TimeoutException if condition unmet [OK]
Common Mistakes:
  • Assuming immediate exception without wait
  • Thinking it clicks without element visible
  • Confusing NoSuchElementException with TimeoutException

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes