Selenium Question 6: What is difference between quit and close

driver.close(): The close() method is used to close the currently active browser window that the WebDriver is focused on.

When multiple tabs or windows are open, and you’ve switched to a specific one using driver.SwitchTo().Window(handle), calling driver.close() will only close that particular tab or window.

This is useful when you want to close one tab after completing operations on it, but continue the rest of the automation in other tabs or windows.

Example use case:

After performing actions on a pop-up or secondary tab, you can close it and return to the main window to continue your test.

driver.quit(): The quit() method is used to close all browser windows or tabs that were opened by the WebDriver instance.

This completely ends the WebDriver session.

It’s typically used at the end of a test run to ensure that all browser instances are closed and system resources are freed.

Example use case:

After the test execution is complete, use driver.quit() to perform a clean shutdown of the browser session.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Testingtalkslatest.com - A project by CreativeHub IT Solutions.
Contact Us At: support@testingtalkslatest.com
Our Partner websites - Classified Hub , CodesToolbox , Smart Fitness Guide , CodesToolbox , Testing Forum
Scroll to Top
0
Would love your thoughts, please comment.x
()
x