• Driver.close(): It is used to close the browser or page currently in focus.
close() is a webdriver command which closes the browser window which is currently in focus.
During the automation process, if there are more than one browser window opened, then the close() command will close only the current browser window which is having focus at that time. The remaining browser windows will not be closed. The following code can be used to close the current browser window:
driver.close() //where, ‘driver’ is the Webdriver object.
• Driver.quit() : It is used to shut down the webdriver and close all instances associated to webdriver.
You should use driver.quit whenever you want to end the program. It will close all opened browser window and terminates the WebDriver session. If you do not use driver.quit at the end of program, WebDriver session will not close properly and files would not be cleared off memory. This may result in memory leak errors.
If the Automation process opens only a single browser window, the close() and quit() commands work in the same way. Both will differ in their functionality when there are more than one browser window opened during Automation.