Bird
Raised Fist0
Selenium Javatesting~20 mins

FluentWait with polling in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
FluentWait Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of FluentWait polling interval behavior
What will be the output of the following Selenium Java code snippet using FluentWait with polling every 500 milliseconds?
Selenium Java
FluentWait<WebDriver> wait = new FluentWait<>(driver)
    .withTimeout(Duration.ofSeconds(3))
    .pollingEvery(Duration.ofMillis(500))
    .ignoring(NoSuchElementException.class);

long start = System.currentTimeMillis();
try {
    wait.until(driver -> driver.findElement(By.id("nonexistent")) != null);
} catch (TimeoutException e) {
    long duration = System.currentTimeMillis() - start;
    System.out.println("Waited approximately " + duration + " ms");
}
AWaited approximately 500 ms
BWaited approximately 3000 ms
CWaited approximately 1500 ms
DWaited approximately 3500 ms
Attempts:
2 left
💡 Hint
Consider how many times the polling happens within the timeout period.
❓ assertion
intermediate
1:30remaining
Correct assertion for FluentWait polling success
Which assertion correctly verifies that a FluentWait with polling found the element within the timeout?
Selenium Java
WebElement element = wait.until(driver -> driver.findElement(By.id("submitBtn")));
// Which assertion below is correct?
AassertNull(element);
BassertTrue(element == null);
CassertFalse(element.isDisplayed());
DassertNotNull(element);
Attempts:
2 left
💡 Hint
If the element is found, it should not be null.
🔧 Debug
advanced
2:00remaining
Identify the bug in FluentWait polling code
What is the bug in this FluentWait polling code snippet?
Selenium Java
FluentWait<WebDriver> wait = new FluentWait<>(driver)
    .withTimeout(Duration.ofSeconds(5))
    .pollingEvery(Duration.ofSeconds(2))
    .ignoring(NoSuchElementException.class);

WebElement element = wait.until(driver -> driver.findElement(By.id("dynamicElement")));
APolling interval is too long compared to timeout, causing fewer polls than expected
BIgnoring NoSuchElementException is incorrect here
CTimeout duration must be less than polling interval
DFluentWait requires pollingEvery to be set in milliseconds, not seconds
Attempts:
2 left
💡 Hint
Check the relationship between polling interval and timeout duration.
🧠 Conceptual
advanced
1:30remaining
Why use FluentWait with polling in Selenium?
What is the main advantage of using FluentWait with a polling interval over a simple implicit wait in Selenium?
AImplicit wait can only be used with CSS selectors
BImplicit wait is faster because it polls more frequently
CFluentWait allows customizing polling frequency and ignoring specific exceptions, providing more control
DFluentWait disables waiting and immediately throws exceptions
Attempts:
2 left
💡 Hint
Think about flexibility and control over waiting behavior.
❓ framework
expert
2:30remaining
Best practice for FluentWait locator usage
In a Selenium test framework using FluentWait with polling, which locator strategy is best practice to ensure reliable element detection?
AUse stable, unique locators like IDs or data-test attributes instead of XPath or CSS selectors that may change
BAlways use XPath locators because they are the fastest
CUse absolute XPath paths for precise element location
DUse CSS selectors with :nth-child() for all elements
Attempts:
2 left
💡 Hint
Consider locator stability and maintainability.

Practice

(1/5)
1. What is the main purpose of using FluentWait in Selenium Java?
easy
A. To throw an exception as soon as an element is not found
B. To wait for an element with a custom timeout and polling interval
C. To immediately find an element without waiting
D. To perform actions on elements without any wait

Solution

  1. Step 1: Understand FluentWait functionality

    FluentWait allows waiting for a condition with a custom timeout and polling frequency.
  2. Step 2: Compare options with FluentWait purpose

    Only To wait for an element with a custom timeout and polling interval describes waiting with custom timeout and polling, which matches FluentWait's use.
  3. Final Answer:

    To wait for an element with a custom timeout and polling interval -> Option B
  4. Quick Check:

    FluentWait = custom wait with polling [OK]
Hint: FluentWait customizes wait time and checks repeatedly [OK]
Common Mistakes:
  • Confusing FluentWait with immediate findElement
  • Thinking FluentWait throws exception immediately
  • Assuming FluentWait skips polling
2. Which of the following is the correct way to create a FluentWait object with polling every 500 milliseconds?
easy
A. new FluentWait(driver).pollingEvery(Duration.ofMillis(500))
B. new FluentWait(driver).pollingEvery(500, TimeUnit.MILLISECONDS)
C. new FluentWait(driver).pollingEvery(500)
D. new FluentWait(driver).pollingEvery(Duration.ofSeconds(500))

Solution

  1. Step 1: Check correct Duration usage for pollingEvery

    pollingEvery expects a Duration object, so Duration.ofMillis(500) is correct for 500 ms.
  2. Step 2: Analyze other options for syntax errors

    new FluentWait(driver).pollingEvery(Duration.ofSeconds(500)) uses seconds instead of milliseconds; B uses deprecated TimeUnit syntax; C uses int without Duration.
  3. Final Answer:

    new FluentWait(driver).pollingEvery(Duration.ofMillis(500)) -> Option A
  4. Quick Check:

    pollingEvery needs Duration.ofMillis for milliseconds [OK]
Hint: Use Duration.ofMillis for polling intervals in FluentWait [OK]
Common Mistakes:
  • Using Duration.ofSeconds instead of ofMillis for milliseconds
  • Passing int directly without Duration
  • Using deprecated TimeUnit with pollingEvery
3. What will happen when the following FluentWait code runs if the element appears after 3 seconds?
Wait<WebDriver> wait = new FluentWait<>(driver)
  .withTimeout(Duration.ofSeconds(5))
  .pollingEvery(Duration.ofSeconds(1))
  .ignoring(NoSuchElementException.class);

WebElement element = wait.until(d -> d.findElement(By.id("dynamicElement")));
System.out.println(element.getText());
medium
A. The code waits full 5 seconds then throws TimeoutException
B. The code throws NoSuchElementException immediately
C. The element is found and its text is printed after about 3 seconds
D. The code prints null because element is not found

Solution

  1. Step 1: Understand FluentWait behavior with polling and timeout

    The wait polls every 1 second up to 5 seconds, ignoring NoSuchElementException until element appears.
  2. Step 2: Analyze timing and result

    Since element appears after 3 seconds, wait finds it before timeout and prints its text.
  3. Final Answer:

    The element is found and its text is printed after about 3 seconds -> Option C
  4. Quick Check:

    FluentWait polls until element found or timeout [OK]
Hint: FluentWait polls repeatedly until element found or timeout [OK]
Common Mistakes:
  • Expecting immediate exception on missing element
  • Assuming wait always waits full timeout
  • Thinking element text prints null if not found
4. Identify the error in this FluentWait code snippet:
Wait<WebDriver> wait = new FluentWait<>(driver)
  .withTimeout(Duration.ofSeconds(10))
  .pollingEvery(500)
  .ignoring(NoSuchElementException.class);

WebElement element = wait.until(d -> d.findElement(By.id("test")));
medium
A. pollingEvery should use Duration, not int
B. withTimeout should be in milliseconds, not seconds
C. Ignoring NoSuchElementException is not allowed
D. FluentWait cannot be used with WebDriver

Solution

  1. Step 1: Check pollingEvery parameter type

    pollingEvery expects a Duration object, but 500 (int) is passed, causing a compile error.
  2. Step 2: Verify other method usages

    withTimeout(Duration.ofSeconds(10)) is correct; ignoring NoSuchElementException is valid; FluentWait works with WebDriver.
  3. Final Answer:

    pollingEvery should use Duration, not int -> Option A
  4. Quick Check:

    pollingEvery requires Duration parameter [OK]
Hint: pollingEvery needs Duration, not plain int [OK]
Common Mistakes:
  • Passing int directly to pollingEvery
  • Confusing withTimeout units
  • Thinking ignoring exceptions is invalid
5. You want to wait up to 10 seconds for an element with id "submitBtn" to appear, checking every 2 seconds, and ignoring both NoSuchElementException and ElementNotVisibleException. Which FluentWait code snippet correctly implements this?
hard
A. new FluentWait<>(driver) .withTimeout(Duration.ofSeconds(10)) .pollingEvery(Duration.ofSeconds(2)) .ignoring(NoSuchElementException.class) .until(d -> d.findElement(By.id("submitBtn")));
B. new FluentWait<>(driver) .withTimeout(Duration.ofSeconds(10)) .pollingEvery(Duration.ofSeconds(2)) .ignoring(NoSuchElementException.class ElementNotVisibleException.class) .until(d -> d.findElement(By.id("submitBtn")));
C. new FluentWait<>(driver) .withTimeout(10) .pollingEvery(2) .ignoring(NoSuchElementException.class) .ignoring(ElementNotVisibleException.class) .until(d -> d.findElement(By.id("submitBtn")));
D. new FluentWait<>(driver) .withTimeout(Duration.ofSeconds(10)) .pollingEvery(Duration.ofSeconds(2)) .ignoring(NoSuchElementException.class) .ignoring(ElementNotVisibleException.class) .until(d -> d.findElement(By.id("submitBtn")));

Solution

  1. Step 1: Check timeout and polling interval syntax

    withTimeout and pollingEvery correctly use Duration.ofSeconds(10) and Duration.ofSeconds(2) in new FluentWait<>(driver) .withTimeout(Duration.ofSeconds(10)) .pollingEvery(Duration.ofSeconds(2)) .ignoring(NoSuchElementException.class) .ignoring(ElementNotVisibleException.class) .until(d -> d.findElement(By.id("submitBtn")));.
  2. Step 2: Verify ignoring multiple exceptions

    new FluentWait<>(driver) .withTimeout(Duration.ofSeconds(10)) .pollingEvery(Duration.ofSeconds(2)) .ignoring(NoSuchElementException.class) .ignoring(ElementNotVisibleException.class) .until(d -> d.findElement(By.id("submitBtn"))); chains .ignoring() calls for each exception, which is valid. new FluentWait<>(driver) .withTimeout(Duration.ofSeconds(10)) .pollingEvery(Duration.ofSeconds(2)) .ignoring(NoSuchElementException.class, ElementNotVisibleException.class) .until(d -> d.findElement(By.id("submitBtn"))); tries to pass two exceptions in one call, which is invalid.
  3. Step 3: Confirm other options

    new FluentWait<>(driver) .withTimeout(10) .pollingEvery(2) .ignoring(NoSuchElementException.class) .ignoring(ElementNotVisibleException.class) .until(d -> d.findElement(By.id("submitBtn"))); uses int instead of Duration, causing errors. new FluentWait<>(driver) .withTimeout(Duration.ofSeconds(10)) .pollingEvery(Duration.ofSeconds(2)) .ignoring(NoSuchElementException.class) .until(d -> d.findElement(By.id("submitBtn"))); ignores only one exception, missing ElementNotVisibleException.
  4. Final Answer:

    new FluentWait<>(driver) .withTimeout(Duration.ofSeconds(10)) .pollingEvery(Duration.ofSeconds(2)) .ignoring(NoSuchElementException.class) .ignoring(ElementNotVisibleException.class) .until(d -> d.findElement(By.id("submitBtn"))); -> Option D
  5. Quick Check:

    Chain ignoring() for multiple exceptions with Duration times [OK]
Hint: Chain ignoring() for each exception; use Duration for times [OK]
Common Mistakes:
  • Passing multiple exceptions in one ignoring() call
  • Using int instead of Duration for time values
  • Ignoring only one exception when multiple needed
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard