Cleaning up the WebDriver in Selenium using C#

The below simple code will allow you to close the WebDriver once the Execution is done. It’s always a good practice to run the TestCase in a new instance of WebDriver rather than in the old one as if we run the same browser there will be some caching issues

 

//Checks whether Driver is not null and then kills the WebDriver using Quit
 if (WebDriver != null)
 {
         WebDriver.Quit();
         WebDriver = null;
                    
 }

 

You may also like...