which one to use? driver.close() / .quit()

There are different ways to close browser[s] using selenium after tests are run.

Depending on scenarios, if single or multiple browsers are opened, we can close or quit browser.

let’s see the usage of close, quit and dispose methods.


driver.close() method will close current browser / browser window, that is in focus or hold by the driver (driver means WebDriver driver).
If there are more than one browser opened, let’s say we click on a link and browser opened in a new window, and we need to close all the browsers that are opened by the driver instance, then use driver.quit().

driver.quit() / driver.dispose()

this method basically calls the dispose() method, to close all the browsers [including browser windows] that are opened by the driver instance and to dispose the driver object itself to safely end the session.

Whether single or multiple browser windows opened, it’s better to use driver.quit() always to avoid memory leakage, else driver session files would not remove from hard disc.

Content posted is based on learning or working experience,
Share the post with others if find useful,
Any queries?, leave comments or discuss on our facebook:qavalidation.com, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *