0
0
Selenium Javatesting~10 mins

Why synchronization eliminates timing failures in Selenium Java - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to wait for the element to be visible before clicking.

Selenium Java
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement element = wait.until(ExpectedConditions.[1](By.id("submitBtn")));
element.click();
Drag options to blanks, or click blank then click option'
ApresenceOfElementLocated
BelementToBeClickable
CvisibilityOfElementLocated
DinvisibilityOfElementLocated
Attempts:
3 left
💡 Hint
Common Mistakes
Using presenceOfElementLocated which only checks if element is in DOM but not visible.
Using invisibilityOfElementLocated which waits for element to disappear.
2fill in blank
medium

Complete the code to pause the test execution for 5 seconds (not recommended but sometimes used).

Selenium Java
try {
    Thread.[1](5000);
} catch (InterruptedException e) {
    e.printStackTrace();
}
Drag options to blanks, or click blank then click option'
Await
Bsleep
Cpause
Ddelay
Attempts:
3 left
💡 Hint
Common Mistakes
Using wait() which is an Object method and requires synchronization.
Using delay() or pause() which do not exist in Thread class.
3fill in blank
hard

Fix the error in the explicit wait code to wait until the element is clickable.

Selenium Java
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));
WebElement button = wait.until(ExpectedConditions.[1](By.id("loginBtn")));
button.click();
Drag options to blanks, or click blank then click option'
AelementToBeClickable
BvisibilityOfElementLocated
CpresenceOfElementLocated
DelementToBeVisible
Attempts:
3 left
💡 Hint
Common Mistakes
Using visibilityOfElementLocated which waits for visibility but not clickability.
Using elementToBeVisible which does not exist.
4fill in blank
hard

Fill both blanks to create a fluent wait that ignores NoSuchElementException and waits 20 seconds polling every 2 seconds.

Selenium Java
Wait<WebDriver> wait = new FluentWait<>(driver)
    .withTimeout(Duration.ofSeconds([1]))
    .pollingEvery(Duration.ofSeconds([2]))
    .ignoring([3].class);
Drag options to blanks, or click blank then click option'
A20
B10
C2
DNoSuchElementException
Attempts:
3 left
💡 Hint
Common Mistakes
Setting polling interval longer than timeout.
Ignoring wrong exception types.
5fill in blank
hard

Fill all three blanks to create a custom ExpectedCondition that waits until the page title contains 'Dashboard'.

Selenium Java
ExpectedCondition<Boolean> titleContainsDashboard = driver -> driver.getTitle().[1]("[2]") [3];
Drag options to blanks, or click blank then click option'
Acontains
BDashboard
C? true : false
Dequals
Attempts:
3 left
💡 Hint
Common Mistakes
Using equals instead of contains which is too strict.
Not using ternary operator causing syntax errors.