0 votes
1 view
in Devops and Agile by (19.8k 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 (63.4k points)

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

driver.close() and driver.quit() are 2 totally different ways 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 current browser window on which the focus is set.

driver.quit() – It essentially calls the driver.dispose method that successively closes all the browser windows and ends the WebDriver session graciously.

You should use the driver.quit() whenever you want to end the program. It will shut 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 won't shut properly and files wouldn't 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 one browser window open and you use the driver.close(), it will quit the webdriver session. The webdriver will not stay active.

To know more about Selenium, you can go through the Selenium course page by Intellipaat

Watch this video on Selenium Tutorial for Beginners

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...