A Custom ExpectedCondition is a user-defined condition that Selenium waits for before proceeding. It helps handle specific scenarios not covered by built-in conditions.
Click to reveal answer
intermediate
How do you create a Custom ExpectedCondition in Selenium Java?
You create a Custom ExpectedCondition by implementing the ExpectedCondition<T> interface and overriding the apply method with your condition logic.
Click to reveal answer
beginner
Why use Custom ExpectedConditions instead of Thread.sleep()?
Custom ExpectedConditions wait only as long as needed for a condition, making tests faster and more reliable than fixed waits like Thread.sleep().
Click to reveal answer
intermediate
Example: What does this Custom ExpectedCondition do?
A. findElement should be replaced with findElements
B. Using lambda expression is not allowed for ExpectedCondition
C. Returning false instead of null causes wait.until to stop waiting prematurely
D. Missing try-catch block for NoSuchElementException
Solution
Step 1: Understand ExpectedCondition return rules
ExpectedCondition should return null to continue waiting, true to stop waiting successfully.
Step 2: Analyze the code's return values
Returning false causes wait.until to stop waiting and throw TimeoutException immediately, which is not desired.
Final Answer:
Returning false instead of null causes wait.until to stop waiting prematurely -> Option C
Quick Check:
Return null to keep waiting, not false [OK]
Hint: Return null to wait longer, not false [OK]
Common Mistakes:
Returning false instead of null to continue wait
Assuming lambda is invalid
Ignoring exception handling
5. You want to create a custom ExpectedCondition that waits until a list of elements with class 'item' contains at least 3 visible elements. Which implementation correctly achieves this?