Difference between webdriver.Dispose(), .Close() and .Quit()

Difference between webdriver.Dispose(), .Close() and .Quit()

Of the three methods, dispose() is only used in C# tests and means the exact same thing as quit(). That is, it will close all the windows currently opened by the WebDriver and safely end the session. 

driver.Quit();

driver.Dispose();

Close() is different in that it only closes the currently focused window. It is best to use this when there are multiple windows being used, in order to close only one of the windows when we are finished using it.

// Switch to the newly opened tab
var windowHandle2 = driver.WindowHandles[1];
driver.SwitchTo().Window(windowHandle2);

// Retrieve the title from the new tab
Console.WriteLine(driver.Title);

// Close the current focused tab
driver.Close();

Leave a reply

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

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.