Testing / Selenium Interview questions
What is the difference between Thread.sleep() and WebDriverWait?
Both pause execution, but for fundamentally different reasons and with very different reliability.
| Thread.sleep() | WebDriverWait |
| Fixed, unconditional pause | Polls a condition, exits as soon as it's true |
| Wastes time if the app is ready sooner | Only waits as long as actually necessary |
| Still fails if the app is slower than the sleep duration | Waits up to a timeout, adapting to real conditions |
Thread.sleep() is a blunt instrument - too short and it's flaky, too long and it slows down every single test that hits it, even the ones where the app happened to be ready instantly. WebDriverWait avoids both problems by checking the actual condition repeatedly instead of guessing a fixed duration.
More Related questions...