Challenge - 5 Problems
Custom ExpectedCondition Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this custom ExpectedCondition?
Consider the following Java Selenium code snippet defining a custom ExpectedCondition. What will be the result of calling apply(driver) if the element with id 'status' has text 'Complete'?
Selenium Java
ExpectedCondition<Boolean> isStatusComplete = new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
WebElement status = driver.findElement(By.id("status"));
return "Complete".equals(status.getText());
}
};
// Assume driver.findElement(By.id("status")).getText() returns "Complete"Attempts:
2 left
💡 Hint
Think about what the apply method returns when the element text matches "Complete".
✗ Incorrect
The apply method returns true if the element's text equals "Complete". Since the element's text is "Complete", the method returns true.
❓ assertion
intermediate2:00remaining
Which assertion correctly verifies the custom ExpectedCondition?
Given a custom ExpectedCondition named isButtonEnabled that returns true when a button is enabled, which assertion correctly verifies this condition in a test?
Selenium Java
ExpectedCondition<Boolean> isButtonEnabled = driver -> driver.findElement(By.id("submitBtn")).isEnabled();Attempts:
2 left
💡 Hint
Remember to call apply(driver) to get the boolean result before asserting.
✗ Incorrect
The apply method returns a Boolean, so assertTrue with isButtonEnabled.apply(driver) correctly asserts the condition is true.
🔧 Debug
advanced2:00remaining
Why does this custom ExpectedCondition cause a NoSuchElementException?
Examine the custom ExpectedCondition below. Why might it throw NoSuchElementException during execution?
Selenium Java
ExpectedCondition<Boolean> isVisible = driver -> {
WebElement elem = driver.findElement(By.cssSelector(".my-element"));
return elem.isDisplayed();
};Attempts:
2 left
💡 Hint
Consider what happens if the element is not present in the DOM when findElement is called.
✗ Incorrect
findElement throws NoSuchElementException immediately if the element is not found. The ExpectedCondition should handle this or use findElements.
❓ framework
advanced2:00remaining
Which custom ExpectedCondition implementation correctly waits for an element's text to contain a substring?
Select the correct custom ExpectedCondition that waits until the element with id 'message' contains the substring 'Success'.
Attempts:
2 left
💡 Hint
Look for the condition that checks if the text contains the substring, not equals or starts/ends with it.
✗ Incorrect
Option C correctly checks if the element's text contains the substring "Success".
🧠 Conceptual
expert2:00remaining
What is the main advantage of using a custom ExpectedCondition in Selenium tests?
Why would a tester create a custom ExpectedCondition instead of using built-in ones?
Attempts:
2 left
💡 Hint
Think about situations where built-in conditions are not enough.
✗ Incorrect
Custom ExpectedConditions allow waiting for specific or complex states that built-in ones do not support.