Close() and Quit() method in Selenium WebDriver

In the previous post, we have written a simple program. In this post, we will learn about the close() and Quit() method in Selenium Webdriver.

Both the methods are used for closing the browser instances. Let’s understand the difference between them.

1. Close() method:

Close() method closes the browser instance which was opened by the WebDriver. Suppose, during execution Webdriver had opened multiple browser windows. When close() method is called, it will close only the browser instance opened by it.

e.g. We will considering testingpool.com. We need to click on the first link “Selenium Introduction” at selenium tutorial page which will open another window of browser. If we use the close method, it closes the first browser instance opened by it.

Code for using Close() method:


2. Quit() method: 

It closes all the browser window i.e. destroy the WebDriver instance. Suppose, during execution Webdriver had opened multiple browser windows. When quit() method is called, it will close all the browser window opened by Selenium WebDriver.

Don't Forget Note Means Important Remember ForgettingIt does not close the browsers which are not opened by WebDriver.

We will take the same example as above, and see the difference. This time it will close all the browser windows.


Ask Question
Have any question or suggestion for us?Please feel free to post in  Q&A Forum

 

Writing the First Program in Selenium
Different Types Of Wait in Selenium
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...

4 Responses

  1. San Aryal says:

    I saw your Lean FT YouTube video which was really helpful. I could not find other parts. Any plans to post them?

  2. Thanks for appreciation.. Yes, I am planning to post more videos on that.. keep following..

  3. Dipesh Tongiya says:

    How to handle or bypass Distil Network detection through selenium webDriver.

  1. August 16, 2015

    […] the previous post, we have seen the difference between close() and Quit() method of WebDriver. In this post , we will see different types of wait commands available in […]

Leave a Reply

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