Challenge - 5 Problems
ExpectedConditions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of waiting for element visibility
What will be the result of this Selenium Java code snippet when the element with id 'submitBtn' becomes visible within 10 seconds?
Selenium Java
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("submitBtn"))); System.out.println(element.isDisplayed());
Attempts:
2 left
💡 Hint
visibilityOfElementLocated waits until the element is visible on the page.
✗ Incorrect
The ExpectedConditions.visibilityOfElementLocated waits up to the specified time for the element to be visible. If it becomes visible, it returns the WebElement, so isDisplayed() returns true.
❓ assertion
intermediate2:00remaining
Correct assertion for element to be clickable
Which assertion correctly verifies that a button with id 'loginBtn' is clickable using ExpectedConditions in Selenium Java?
Selenium Java
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5)); WebElement button = wait.until(ExpectedConditions.elementToBeClickable(By.id("loginBtn")));
Attempts:
2 left
💡 Hint
elementToBeClickable means the element is visible and enabled.
✗ Incorrect
ExpectedConditions.elementToBeClickable returns the element only if it is visible and enabled. So asserting isEnabled() and isDisplayed() true confirms it is clickable.
🔧 Debug
advanced2:00remaining
Identify the error in ExpectedConditions usage
What is the error in this Selenium Java code snippet?
Selenium Java
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(8)); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@class='content']")));
Attempts:
2 left
💡 Hint
presenceOfElementLocated waits only for element in DOM, not visibility.
✗ Incorrect
presenceOfElementLocated waits for the element to be present in the DOM but does not guarantee it is visible or interactable. This can cause issues if interaction is attempted immediately after.
🧠 Conceptual
advanced2:00remaining
Understanding ExpectedConditions stalenessOf
What does the ExpectedConditions.stalenessOf(WebElement element) condition check in Selenium Java?
Attempts:
2 left
💡 Hint
Staleness means the element reference is outdated.
✗ Incorrect
stalenessOf waits until the element is no longer attached to the DOM, meaning it has been removed or refreshed. This is useful to wait for page updates.
❓ framework
expert3:00remaining
Best practice for waiting for multiple conditions
In Selenium Java, which approach correctly waits until both an element with id 'username' is visible and a button with id 'submit' is clickable before proceeding?
Attempts:
2 left
💡 Hint
Chain sequential wait.until calls to ensure both conditions.
✗ Incorrect
Chaining wait.until calls first waits for the username field to be visible, then for the submit button to be clickable. ExpectedConditions does not provide 'and' or 'or'; sequential waits are a standard best practice to ensure both conditions before proceeding.