Careeroza
Close vs Quit
The Difference
| Method | What it closes | Session after |
|---|---|---|
driver.close() | only the current window or tab | still alive if other windows are open |
driver.quit() | all windows and the driver process | ended; any later call fails |
Using the Driver After Quit
driver.quit();
driver.getTitle(); // session is goneExample
The second line throws:
Run QuitTest.main()Example output
Exception in thread "main" org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()? Build info: version: '4.25.0', revision: '8a8aea2337'
Tip: Put driver.quit() in a finally block (and later in a TestNG @AfterMethod) so the browser closes even when the test fails.
WebDriver driver = new ChromeDriver();
try {
driver.get("https://shopease.example.com");
// test steps ...
} finally {
driver.quit();
}