0
0
Selenium Javatesting~20 mins

Custom ExpectedCondition in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Custom ExpectedCondition 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 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"
Atrue
Bfalse
CTimeoutException is thrown
DNoSuchElementException is thrown
Attempts:
2 left
💡 Hint
Think about what the apply method returns when the element text matches "Complete".
assertion
intermediate
2: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();
AassertNull(isButtonEnabled.apply(driver));
BassertTrue(isButtonEnabled.apply(driver));
CassertEquals(isButtonEnabled, true);
DassertFalse(isButtonEnabled.apply(driver));
Attempts:
2 left
💡 Hint
Remember to call apply(driver) to get the boolean result before asserting.
🔧 Debug
advanced
2: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();
};
ABecause findElement throws NoSuchElementException if the element is not found immediately
BBecause isDisplayed() throws NoSuchElementException if element is hidden
CBecause the lambda syntax is invalid and causes runtime error
DBecause ExpectedCondition must return WebElement, not Boolean
Attempts:
2 left
💡 Hint
Consider what happens if the element is not present in the DOM when findElement is called.
framework
advanced
2: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'.
A
ExpectedCondition&lt;Boolean&gt; textContains = driver -&gt; {
    WebElement el = driver.findElement(By.id("message"));
    return el.getText().equals("Success");
};
BExpectedCondition<Boolean> textContains = driver -> driver.findElement(By.id("message")).getText().startsWith("Success");
CExpectedCondition<Boolean> textContains = driver -> driver.findElement(By.id("message")).getText().contains("Success");
DExpectedCondition<Boolean> textContains = driver -> driver.findElement(By.id("message")).getText().endsWith("Success");
Attempts:
2 left
💡 Hint
Look for the condition that checks if the text contains the substring, not equals or starts/ends with it.
🧠 Conceptual
expert
2: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?
ATo automatically retry failed tests without coding
BTo reduce test execution time by skipping waits
CTo avoid using WebDriverWait entirely
DTo wait for complex or specific conditions not covered by built-in ExpectedConditions
Attempts:
2 left
💡 Hint
Think about situations where built-in conditions are not enough.