Testing / Selenium Interview questions
What is the difference between driver.close() and driver.quit()?
These sound similar but operate at very different scopes.
| driver.close() | driver.quit() |
| Closes only the currently focused window/tab | Closes all windows opened by this session |
| The driver session stays alive if other windows remain | Terminates the entire WebDriver session and driver process |
| Used when working with multiple windows and only one should end | Used at the end of a test to fully clean up |
Calling close() when it's the only open window effectively ends the session too, but it doesn't explicitly terminate the underlying driver process the way quit() does - which is why quit(), typically in an @AfterMethod or teardown block, is the safer choice for guaranteed cleanup.
More Related questions...