1

I simply cannot get Selenium to clean up after navigating to a page. (Without the Navigate().GoToURL(), it tears down nicely.) I understand the supposed difference between Close(), Quit(), and Dispose(). I've tried every combination I could think of. I must be missing something. If I have to shut them down myself --if that's the solution... I honestly have no clue, but that's fine. I would just like to know if I am missing something in terms of using Selenium. Any help greatly appreciated.

// no iexplore windows open

IWebDriver f = new InternetExplorerDriver();

f.Navigate().GoToUrl("http://abcdxpq.com");

f.Close();
f.Quit();
f.Dispose();

// iexplore window left open (http://abcdxpq.com)
  • Sounds like a bug with the driver, or maybe a mismatch between selenium, IeDriver, and your IE version. You should only have to use `.Quit();`. I'd also make sure you don't have another stray driver somewhere if you're passing this instance around. – mrfreester Dec 07 '17 at 23:06
  • Just to double check, there are no exceptions being thrown? – mrfreester Dec 07 '17 at 23:09
  • No exceptions...fresh Selenium and drivers etc. – Fred Marsland Dec 08 '17 at 14:12

2 Answers2

0

Looking at your code I feel we need to narrow down to a single line of code to process the tearDown() the IEDriverServer and the Browser instance of InternetExplorerDriver.

As per the current implementation, Driver.Dispose(); shouldn't be used to clean up the WebDriver instance. For a proper cleanup we must be using Driver.Quit();. It's worth to be mentioned that Driver.Quit(); internally calls Driver.Close();.

tearDown() Methods Comparision

  • Driver.Dispose();: It got deprecated currently.
  • Driver.Close(); : It is used to close the current page or the browser (if it is the only page/tab) which is having the focus.
  • Driver.Quit(); : It is used to call the /shutdown endpoint and subsequently kill the WebDriver and the Web Browser instance completely closing all the pages/tabs/windows.

You will get a more detailed discussion in this discussion PhantomJS web driver stays in memory

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I agree, however, it doesn't work that way :) I left all 3 of those calls in to show the order I tried them in (when using them in combination with each other). Quit() by itself, does not work. So I resorted to trying Dispose()...which looked promising, until I navigated to any site. – Fred Marsland Dec 08 '17 at 14:03
  • `Dispose()` is no more an option in current `Selenium` releases. `Quit()` should work else file a bug with seleniumhq. – undetected Selenium Dec 08 '17 at 14:06
  • I think the example in the API doc I was looking at on seleniumhq.org might be a wee bit out of date. :) Thank you for your help. – Fred Marsland Dec 08 '17 at 16:14
0

Figured out what I was doing wrong, or at least what works --given that I believe Quit() is supposed to close all? Anyhow, assuming Quit doesn't quite close all the windows, I still assumed that instantiating and then navigating would only create one window to shut down... it obviously creates 2 :) My bad. This shuts everything down. But maybe there is a problem with the driver, if Quit() is supposed to do the trick?

IWebDriver f = new InternetExplorerDriver(); 

f.Close(); // <- this is what I added. this works for me. nothing left open.

f.Navigate().GoToUrl("http://abcdxpq.com");

f.Quit();
  • hmmm that sounds like a bug as it's not supposed to work that way. I'd check to see if you have the latest version of the IE driver, and if so maybe they'll fix it in an upcoming patch. – mrfreester Dec 08 '17 at 15:55
  • Unfortunately, this solution only worked in this exact form, in the exact place I had it. Once I tried to move the web driver to my automated browsing class, and make calls to it from another, same problem returned. Selenium seems very inconsistent in terms of its window/tab/whatever handling. It seems once navigating to a site, it goes off the rails. Tried too many combinations to post. I ended up choosing iMacros to work with. Very happy with that choice. – Fred Marsland Dec 12 '17 at 16:41