Salvador Dali
Salvador Dali

Reputation: 222969

Close browser completely with selenium C# webdriver

I am doing some automated testing with Selenium C# Webdriver. And after finishing the tests I want to close the browser.

I initialize the driver with the following:

var driver = new ChromeDriver();

And then after doing something I am closing it with

driver.Close();

The browser is correcly closes, but there is a window which starts this browser which is still hanging.enter image description here

Is there a way to close it as well?

Upvotes: 15

Views: 36713

Answers (3)

Ghanshyam Singh
Ghanshyam Singh

Reputation: 1381

This will close browser window as well as Chrome Driver prompt

ChromeOptions options = new ChromeOptions();
options.addArguments("no-sandbox");
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.google.com/");
driver.close();
driver.quit();

Upvotes: 7

Rakhi
Rakhi

Reputation: 204

Always use Driver.Quit(); to close WebDriver and browser

Driver.Quit();

Upvotes: 4

JimEvans
JimEvans

Reputation: 27496

driver.Close() is intended to close popup browser windows, such as those opened by clicking on a link that triggers a window.open() call in JavaScript. To be absolutely certain all resources are released and cleaned up by a driver, use driver.Quit().

Upvotes: 38

Related Questions