0
0
Selenium Javatesting~10 mins

Thread.sleep vs proper waits in Selenium Java - Interactive Practice

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

Complete the code to pause the test execution for 3 seconds using Thread.sleep.

Selenium Java
Thread.sleep([1]);
Drag options to blanks, or click blank then click option'
A300
B3
C3000
D30
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 instead of 3000 causes the sleep to be too short.
Using 30 or 300 is not the correct duration for 3 seconds.
2fill in blank
medium

Complete the code to create an explicit wait that waits up to 10 seconds.

Selenium Java
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds([1]));
Drag options to blanks, or click blank then click option'
A10
B20
C5
D15
Attempts:
3 left
💡 Hint
Common Mistakes
Using 5 or 15 seconds when the requirement is 10 seconds.
Confusing milliseconds with seconds.
3fill in blank
hard

Fix the error in the code to wait until the element with id 'submit' is clickable.

Selenium Java
wait.until(ExpectedConditions.[1](By.id("submit")));
Drag options to blanks, or click blank then click option'
AalertIsPresent
BvisibilityOfElementLocated
CpresenceOfElementLocated
DelementToBeClickable
Attempts:
3 left
💡 Hint
Common Mistakes
Using visibilityOfElementLocated waits only for visibility, not clickability.
Using presenceOfElementLocated waits only for presence in DOM.
4fill in blank
hard

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

Selenium Java
Wait<WebDriver> wait = new FluentWait<>(driver)
    .withTimeout(Duration.ofSeconds([1]))
    .pollingEvery(Duration.ofSeconds([2]))
    .ignoring(NoSuchElementException.class);
Drag options to blanks, or click blank then click option'
A30
B2
C5
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping timeout and polling interval values.
Using too short or too long polling intervals.
5fill in blank
hard

Fill all three blanks to create a stream collector that maps element IDs to their text if text length is greater than 3.

Selenium Java
Map<String, String> texts = elements.stream()
    .filter(e -> e.getText().length() [1] 3)
    .collect(Collectors.toMap(e -> e.getAttribute([2]), e -> e.[3]()));
Drag options to blanks, or click blank then click option'
A>
B"id"
CgetText
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the filter.
Using wrong attribute name instead of 'id'.
Calling wrong method instead of getText().