Understanding driver.close and driver.quit in WebDriver
driver.close and driver.quit are two different methods for closing the browser session in Selenium WebDriver. Understanding both of them and knowing when to use which method is important in your test execution. Therefore, in this article, we have tried to throw light on both these methods.
- driver.close – It closes the the browser window on which the focus is set.
- driver.quit – It basically calls driver.dispose method which in turn closes all the browser windows and ends the WebDriver session gracefully.
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.
The above explanation should clear the difference between driver.close and driver.quit methods in WebDriver. We hope you would find it useful. Let us know your view in comments.
Hi,
Everytime i use driver.quit(), I get an error:
Caused by: java.lang.NullPointerException: Unable to find executable for: taskkill
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:250), but when I change the code to java.close(), it does shut down the page. Can you please explain why. Thanks.
Hi, I am not author of this post, buy at first, read again difference between close and quit which is described in post.
When you call quit, then its try to close session and how? It depends on OS! From your error message, you are running on Windows (taskkill is basic Win tool), so its look like that you have not these tools in your PATH (there should be C:\Windows\system32 where these utilities are stored)
HI, I used the driver.quit() but the browser is not closing.
Please help me
HI, I need to manually stop the test while its running with clicking of stop button is that possible?
can i user driver.close(); and driver.quit(); in the same class. If yes, what will be exception thrown