1

I want browser auto exit browser when timeout.

I was debugging it show correct in my mind. But when to run the application, I don't know it does not exit browser after waiting_timeout seconds.

My code like:

int waiting_timeout = 60;
_tmExcute = DateTime.Now;
// Do any thing
if ((DateTime.Now - _tmExcute).TotalSeconds > waiting_timeout)
{
    ExitALL();      // exit browser.
}
joe
  • 67
  • 1
  • 1
  • 7
  • Check this answer: http://stackoverflow.com/questions/15067107/difference-between-webdriver-dispose-close-and-quit. Look like you need to call driver.quit() – csharpfolk Feb 22 '16 at 08:56

2 Answers2

0

Use driver.quit(), this will quit the driver and close every associated window.

if ((DateTime.Now - _tmExcute).TotalSeconds > waiting_timeout)
{
    driver.quit();
}

If you have only one window open driver.close() will work also.

Guy
  • 46,488
  • 10
  • 44
  • 88
0

On timeout, Selenium usually throws an exception. So your expression ((DateTime.Now - _tmExcute).TotalSeconds > waiting_timeout) will never be false. You should use try ... catch instead.

Although it's better, if you use a test framework, to place the WebDriver shutdown in your [TestCleanup] or [TearDown]. Then you don't have to explicitly take care of the exceptions time and time again.

Kim Homann
  • 3,042
  • 1
  • 17
  • 20