Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in DevOps and Agile by (19.7k points)

In my batch execution, multiple browsers with multiple tabs are getting opened for the first scenario. I wanted to close all these browsers before starting the second scenario.

Driver.close() is just closing one tab of the browser. Driver.quit() is closing all the browsers and also ending the WebDriver session. So, am unable to run the batch execution. Please provide a solution for this.

1 Answer

0 votes
by (62.9k points)

You should understand difference between driver.close() and driver.quit()

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.

driver.close() – It closes the browser window on which the focus is set.

driver.quit() – It basically calls the driver.dispose method which in turn closes all the browser windows and ends the WebDriver session gracefully.

You should use the 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 the driver.quit at the end of the program, WebDriver session will not close properly and files would not be cleared off memory. This may result in memory leak errors.

In your case, you have to use the driver.close() which will close the current window and keeps driver active.

Just to add - if there is only browser window open and you use the driver.close(), it will quit the webdriver session. The webdriver will not stay active.

To learn in-depth about Selenium, sign up for an industry based Selenium course.

Browse Categories

...