Quit() vs Close() in Selenium WebDriver

I have been seeing a lot of questions everywhere and want to discuss about Quit() vs Close()

Close()

Use the following code.

//initiates the FirefoxDriver
WebDriver driver = new FirefoxDriver();
//Opens the Google Page
driver.get("http://google.com");
//Once on the Google page right click on any link (say images) and open it in a new tab
Thread.sleep(20000l);
//Now we have two browser windows opened with this webdriver instance. So when driver.close() is called it will
//close only the parent browser window, it will not close the new tab window which we opened.
driver.close();

Quit()

Use the following code.

//initiates the FirefoxDriver
WebDriver driver = new FirefoxDriver();
//Opens the Google Page
driver.get("http://google.com");
//Once on the Google page right click on any link (say images) and open it in a new tab
Thread.sleep(20000l);
//Now we have two browser windows opened with this webdriver instance. So when driver.<del>close</del>quit() is called it will
//close all browser windows, it will close both of the opened browser windows associated with the driver object..
driver.quit();

Thanks,
Khaja

Advertisements

Fuze Hangout on Wednesday, 01/15/2014

Thanks All For Showing Interest Joining This Awesome Journey…

We will be meeting on Wednesday, 01/15/2014, for a quick 30 minutes hangout. I have looked at various free conference options and found Fuze to be more helpful.

Here are the meeting invite details.

Meeting Number: 22768879

Join Online Meeting:
http://fuze.me/22768879

To join from a phone:
Toll: +12014794595

Thanks,
Khaja