Manuals / Selenium WebDriver / Chapter 3

A · WebDriver Core · beginner · Week 1–2 · Chapter 3 of 12

Explicit waits — never Thread.sleep

Flaky Selenium is almost always wrong waits. WebDriverWait + ExpectedConditions beat sleep every time.

Path progress
19%

Step 1 of 4

Ban Thread.sleep

sleep(3) hides races. Under CI load, races become flakes. Zero tolerance.

Ban Thread.sleepDrag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →Ban Thread.sleepdrag · tap →Try thisdrag · tap →Follow the dashed drag · tap →

Do this now

Search codebase for sleep/Thread.sleep/time.sleep. Replace all.

Was this step clear?
Chapter learning outcomes
  • Implicit vs explicit waits
  • ExpectedConditions
  • Custom wait conditions
  • FluentWait

Clear these before you leave

Side quest

Ajax wait

Wait for element after AJAX on dynamic_controls — checkbox enabled.