Chapter 3: Handling Waits and Synchronization
Q: What is the difference between presenceOfElementLocated, visibilityOfElementLocated, and elementToBeClickable?
A: presenceOfElementLocated checks that the element exists in the DOM tree (it can be hidden or invisible). visibilityOfElementLocated checks that the element exists in the DOM AND is displayed with non-zero width and height. elementToBeClickable checks that the element is visible AND enabled (not disabled via attribute). For clicking buttons, elementToBeClickable is required. For reading text, visibilityOfElementLocated is required. For hidden inputs/CSRF tokens, presenceOfElementLocated is used.
Q: Why should you never mix implicit and explicit waits in Selenium?
A: The W3C WebDriver specification explicitly warns that mixing implicit and explicit waits causes undefined timeout behavior. Explicit wait polls findElement() internally. If implicit wait is active, every failed poll cycle waits the full implicit duration instead of immediately returning to the polling loop. A 10-second explicit wait can end up taking 100+ seconds. Best practice is to set implicit wait to 0 and exclusively use explicit waits.
Q: How do you handle tests that pass on developer machines but fail intermittently in Jenkins CI?
A: This is classic synchronization flakiness caused by virtualized CI CPU throttling and network latency variance. I resolve it by: (1) Replacing any Thread.sleep() or implicit waits with explicit WebDriverWait and appropriate ExpectedConditions, (2) Waiting for loading overlays/spinners to become invisible before interacting with form fields, (3) Tuning ChromeOptions with --disable-dev-shm-usage and --window-size=1920,1080 to prevent rendering layout shifts, and (4) Centralizing timeouts with configurable CI environment overrides.
Key Point: Know the exact differences between presence, visibility, and clickability cold — it is asked in 90% of automation interviews.
Answer all 4 questions, then submit to see your score.
1. Why is Thread.sleep() bad practice in production test suites?
2. Which ExpectedCondition must you use before calling .click() on an input button?
3. What is the primary difference between WebDriverWait and FluentWait?
4. What happens when you mix implicit wait and explicit wait in Selenium 4?