Recall & Review
beginner
What is the purpose of the <code>ExpectedConditions</code> class in Selenium?The <code>ExpectedConditions</code> class provides a set of common conditions to wait for during Selenium tests, such as waiting for an element to be visible or clickable. It helps make tests more reliable by synchronizing actions with the web page state.Click to reveal answer
beginner
Name three common conditions provided by the
ExpectedConditions class.1.
visibilityOfElementLocated(By locator) - waits until the element is visible.<br>2. elementToBeClickable(By locator) - waits until the element is clickable.<br>3. presenceOfElementLocated(By locator) - waits until the element is present in the DOM.Click to reveal answer
beginner
How do you use
ExpectedConditions with WebDriverWait?You create a
WebDriverWait object with a timeout, then call its until() method passing an ExpectedConditions condition. For example:<br>new WebDriverWait(driver, Duration.ofSeconds(10))
.until(ExpectedConditions.visibilityOfElementLocated(By.id("myId")));
Click to reveal answer
beginner
Why is using
ExpectedConditions better than using Thread.sleep() in tests?ExpectedConditions waits only as long as needed for a condition to be true, making tests faster and more reliable. Thread.sleep() pauses for a fixed time regardless of page state, which can slow tests and cause failures if the wait is too short or too long.Click to reveal answer
beginner
What happens if the condition in
ExpectedConditions is not met within the timeout?If the condition is not met within the specified timeout,
WebDriverWait throws a TimeoutException. This signals that the expected state was not reached in time, and the test can handle this failure accordingly.Click to reveal answer
Which method waits until an element is clickable using
ExpectedConditions?✗ Incorrect
The method
elementToBeClickable(By locator) waits until the element is visible and enabled so it can be clicked.What does
WebDriverWait.until() return when the condition is met?✗ Incorrect
until() returns the result of the condition, often the WebElement found or a Boolean true.Why should you avoid using
Thread.sleep() in Selenium tests?✗ Incorrect
Thread.sleep() pauses for a fixed time regardless of page state, which can slow tests and cause flakiness.What exception is thrown if
ExpectedConditions is not met in time?✗ Incorrect
If the wait times out,
TimeoutException is thrown indicating the condition was not met.Which
ExpectedConditions method waits for an element to be present in the DOM but not necessarily visible?✗ Incorrect
presenceOfElementLocated(By locator) waits for the element to exist in the DOM regardless of visibility.Explain how the
ExpectedConditions class improves test reliability in Selenium.Think about how waiting for elements to be ready helps tests run smoothly.
You got /4 concepts.
Describe how to use
ExpectedConditions with WebDriverWait to wait for an element to be visible.Remember the syntax: new WebDriverWait(driver, Duration).until(condition).
You got /4 concepts.