0
0
Selenium Javatesting~20 mins

ExpectedConditions class in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ExpectedConditions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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());
ANoSuchElementException
Btrue
Cfalse
DTimeoutException
Attempts:
2 left
💡 Hint
visibilityOfElementLocated waits until the element is visible on the page.
assertion
intermediate
2: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")));
AassertTrue(button.isEnabled() && button.isDisplayed());
BassertFalse(button.isEnabled());
CassertNull(button);
DassertEquals(button.getText(), "Submit");
Attempts:
2 left
💡 Hint
elementToBeClickable means the element is visible and enabled.
🔧 Debug
advanced
2: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']")));
ANo error; code waits for element presence correctly.
BBy.xpath locator syntax is invalid.
CDuration.ofSeconds should be replaced with just seconds as int.
DpresenceOfElementLocated does not wait for visibility, so element may not be interactable.
Attempts:
2 left
💡 Hint
presenceOfElementLocated waits only for element in DOM, not visibility.
🧠 Conceptual
advanced
2:00remaining
Understanding ExpectedConditions stalenessOf
What does the ExpectedConditions.stalenessOf(WebElement element) condition check in Selenium Java?
AChecks if the element is no longer attached to the DOM.
BChecks if the element is visible on the page.
CChecks if the element is enabled and clickable.
DChecks if the element's text matches a given string.
Attempts:
2 left
💡 Hint
Staleness means the element reference is outdated.
framework
expert
3: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?
A
wait.until(ExpectedConditions.and(
    ExpectedConditions.visibilityOfElementLocated(By.id("username")),
    ExpectedConditions.elementToBeClickable(By.id("submit"))
));
B
wait.until(ExpectedConditions.or(
    ExpectedConditions.visibilityOfElementLocated(By.id("username")),
    ExpectedConditions.elementToBeClickable(By.id("submit"))
));
C
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username")));
wait.until(ExpectedConditions.elementToBeClickable(By.id("submit")));
D
wait.until(ExpectedConditions.not(
    ExpectedConditions.invisibilityOfElementLocated(By.id("username"))
));
Attempts:
2 left
💡 Hint
Chain sequential wait.until calls to ensure both conditions.