0
0
Selenium Javatesting~5 mins

Thread.sleep vs proper waits in Selenium Java - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What does Thread.sleep() do in Selenium tests?

Thread.sleep() pauses the test execution for a fixed amount of time, regardless of whether the page or element is ready.

Click to reveal answer
beginner
What are 'proper waits' in Selenium?

Proper waits are dynamic waits like Implicit Wait and Explicit Wait that wait only as long as needed for a condition to be true, improving test reliability.

Click to reveal answer
intermediate
Why is Thread.sleep() discouraged in Selenium tests?

Because it causes unnecessary delays and can make tests slower and flaky if the wait time is too short or too long.

Click to reveal answer
intermediate
Give an example of using ExplicitWait in Selenium Java.
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("myElement")));
Click to reveal answer
beginner
What is the main benefit of using proper waits over Thread.sleep()?

Proper waits make tests faster and more reliable by waiting only as long as necessary for elements or conditions, avoiding fixed delays.

Click to reveal answer
What happens when you use Thread.sleep(5000) in a Selenium test?
AThe test pauses exactly 5 seconds regardless of page state
BThe test waits until an element is visible
CThe test waits only if the element is not found
DThe test continues immediately without waiting
Which Selenium wait waits dynamically until a condition is met or timeout occurs?
AExplicit Wait
BThread.sleep()
CSystem.exit()
DHardcoded delay
Why should you avoid using Thread.sleep() in tests?
AIt automatically retries failed steps
BIt speeds up tests too much
CIt makes tests slower and less reliable
DIt only works on Chrome browser
What is the purpose of Implicit Wait in Selenium?
ATo pause test execution for a fixed time
BTo set a default wait time for finding elements
CTo close the browser automatically
DTo take screenshots on failure
Which is a better practice for waiting for an element to appear?
AUsing <code>Thread.sleep()</code>
BUsing <code>driver.quit()</code>
CUsing <code>System.out.println()</code>
DUsing <code>Explicit Wait</code>
Explain the difference between Thread.sleep() and proper waits in Selenium.
Think about fixed vs dynamic waiting.
You got /4 concepts.
    Describe how you would use an explicit wait to wait for an element to be visible.
    Recall the code example with WebDriverWait.
    You got /4 concepts.