0
0
Selenium Javatesting~20 mins

Explicit wait (WebDriverWait) in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Explicit Wait Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this explicit wait code snippet?
Consider the following Selenium Java code using WebDriverWait. What will be the result printed?
Selenium Java
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("submitBtn")));
System.out.println(element.isDisplayed());
Atrue
Bfalse
CTimeoutException
DNoSuchElementException
Attempts:
2 left
💡 Hint
The wait waits until the element is visible or timeout occurs.
assertion
intermediate
2:00remaining
Which assertion correctly verifies the element is clickable using explicit wait?
You want to assert that a button with id 'loginBtn' is clickable before clicking it. Which assertion is correct?
AassertNull(wait.until(ExpectedConditions.elementToBeClickable(By.id("loginBtn"))));
BassertFalse(wait.until(ExpectedConditions.elementToBeClickable(By.id("loginBtn"))).isDisplayed());
CassertTrue(wait.until(ExpectedConditions.elementToBeClickable(By.id("loginBtn"))).isEnabled());
DassertEquals(wait.until(ExpectedConditions.elementToBeClickable(By.id("loginBtn"))), null);
Attempts:
2 left
💡 Hint
Clickable means the element is enabled and visible.
🔧 Debug
advanced
2:00remaining
Why does this explicit wait code throw TimeoutException?
Analyze the code below. Why does it throw TimeoutException even though the element exists?
Selenium Java
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("dynamicElement")));
// The element appears after 7 seconds on the page
AThe wait time is less than the element's appearance delay, so it times out.
BThe locator By.id("dynamicElement") is incorrect and cannot find the element.
CThe element is present but not clickable, causing TimeoutException.
DThe driver is not initialized, causing the wait to fail.
Attempts:
2 left
💡 Hint
Check the wait duration vs element appearance time.
🧠 Conceptual
advanced
2:00remaining
What is the main difference between implicit wait and explicit wait in Selenium?
Choose the correct statement that explains the key difference between implicit and explicit waits.
AImplicit wait is deprecated; explicit wait is the only recommended wait method.
BImplicit wait waits for a specific condition; explicit wait sets a default wait time for all elements.
CImplicit wait only works with JavaScript alerts; explicit wait only works with page loads.
DImplicit wait sets a default wait time for all element searches; explicit wait waits for a specific condition for a particular element.
Attempts:
2 left
💡 Hint
Think about scope and usage of each wait type.
framework
expert
3:00remaining
Which code snippet correctly implements a fluent wait with polling and ignoring exceptions?
Select the code that creates a FluentWait in Selenium Java that polls every 2 seconds, waits up to 15 seconds, and ignores NoSuchElementException.
A
Wait<WebDriver> wait = new FluentWait<>(driver)
  .withTimeout(Duration.ofSeconds(15))
  .ignoring(NoSuchElementException.class)
  .pollingEvery(Duration.ofSeconds(2));
B
Wait<WebDriver> wait = new FluentWait<>(driver)
  .withTimeout(Duration.ofSeconds(15))
  .pollingEvery(Duration.ofSeconds(2))
  .ignoring(NoSuchElementException.class);
C
Wait<WebDriver> wait = new FluentWait<>(driver)
  .pollingEvery(Duration.ofSeconds(15))
  .withTimeout(Duration.ofSeconds(2))
  .ignoring(NoSuchElementException.class);
D
Wait<WebDriver> wait = new FluentWait<>(driver)
  .withTimeout(Duration.ofSeconds(2))
  .pollingEvery(Duration.ofSeconds(15))
  .ignoring(NoSuchElementException.class);
Attempts:
2 left
💡 Hint
Check the order and values of timeout and polling intervals.