Testing / Selenium Interview questions
How do you debug a failing Selenium test?
Since Selenium has no built-in Inspector or trace viewer like some newer frameworks, debugging typically combines a few complementary techniques.
Running in headed mode locally lets you visually watch what the browser actually does at the failing step, rather than reasoning about it purely from stack traces. Adding targeted logging of driver.getPageSource() or a screenshot right before the failing assertion captures the actual DOM state at that moment, which is especially useful for failures that only occur on CI where you can't watch it live.
Attaching a debugger and setting a breakpoint just before the failing line lets you inspect element state, current URL, and locator results interactively. For flaky failures specifically, temporarily increasing explicit wait timeouts and re-running several times helps distinguish a genuine timing issue from a locator that's simply wrong.
More Related questions...