Skip to main content

Difference between driver.close() and driver.quit() command in Selenium with Java

Selenium driver.close()

  • WebDriver's close() method closes the web browser window that the user is currently working on or we can also say the window that is being currently accessed by the WebDriver.
  • The command neither requires any parameter nor does it return any value.
  • When you use driver.close(), only the window that has focus is closed. It is better to use driver.close() when you are dealing with multiple tabs or windows.

Selenium driver.quit()

  • Unlike close() method, quit() method closes down all the windows that the program has opened.
  • Same as close() method, the command neither requires any parameter nor does is return any value. 
  • driver.quit() is used to exit the browser, end the session, tabs, pop-ups etc.
  • quit() is a webdriver command which calls the driver.dispose method, which in turn closes all the browser windows and terminates the WebDriver session.
  • If we do not use quit() at the end of program, the WebDriver session will not be closed properly and the files will not be cleared off memory. This may result in memory leak errors.


public class CloseAndQuit 
    WebDriver driver;
    public void befClass()
        System.setProperty("",System.getProperty("user.dir") + "//drivers//chromedriver");
        driver = new ChromeDriver();
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    public void MyMethod() throws AWTException, InterruptedException
        driver.findElement(By.cssSelector("button[class='btn btn-default btn-twitter']")).click();

Above code will open product page of automation practice website and click on Twitter button, which further will open a new Twitter Window. Hence, there will be 2 windows one with another with Twitter. Once driver.close() command will execute it will close window and twitter window will remain open.

Now,  replace driver.close() with driver.quit(). You will find that both Windows and twitter window are closed. Similar will be the case if you are dealing with multiple tabs with driver.quit() all tabs will be closed and with driver.close() currently focus tab will be closed.

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 windows or tabs opened during Automation.

Submitted by tgoswami on October 6, 2020

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.