1

This problem really confused me a lot. I'm using python selenium do some automatic work. After the work done, i need to close browser(I must use firefox). And I know driver.close() is to close current window and driver.quit() will close all windows and exit browser. The problem is: it doesn't work for me if i am using python file.py to run my code, but work if I setup the driver in python console, here not work is to say it just close my url, but the firefox browser not exit. All above tests have setted firefox_profile. More, i found if i don't set firefox_profile the first way to run my code also working. I think maybe it's a bug for firefox_profile. Wish someone to save my day. My code is just like:

profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)  # custom location
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', download_dir)
profile.set_preference(
    'browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream')
driver = webdriver.Firefox(
    executable_path=gecko_dir, firefox_profile=profile)
driver.get(someurl)
driver.quit()# which will close my session, my url, my current window but not exit browser

the versions i'am using:

  • python 3.5.3
  • selenium 3.4.3
  • firefox 55.0.1
  • geckodriver 0.18.0
chenkh
  • 69
  • 1
  • 9
  • What do you exactly mean by `just close my url, but the firefox browser not exit`? Is the Firefox Browser and WebDriver instance getting closed gracefully? – undetected Selenium Aug 16 '17 at 06:21
  • after the driver.quit() done, my browser can not exit, it still keep one window on, which is a blank window - a "New Tab" no the other things. Is that clear? – chenkh Aug 16 '17 at 06:33
  • The browser windows initiated by the webdriver instance is bound to get closed (killed) once you invoke `driver.quit()`. So the `blank window` may be a result of some other user interections. Are you on Selenium 3.5.0 with latest GeckoDriver v.0.18.0 and Mozilla Firefox 53.0? – undetected Selenium Aug 16 '17 at 06:39
  • as i supplement just now, my selenium version 3.4.3 and the geckodriver and firefox are both the latest version. No the others interrections. Problem is still there – chenkh Aug 16 '17 at 06:43
  • Can you close down all your apps and get a system restart and simply execute your script? – undetected Selenium Aug 16 '17 at 06:45
  • Oh shit, i'am stupid. There is really some other interaction that I did find. There's another driver opened. thanks a lot – chenkh Aug 16 '17 at 07:03
  • ok ok, i will accept it. – chenkh Aug 16 '17 at 08:14

1 Answers1

0

While we work with Selenium 3.5.0 with latest GeckoDriver v.0.18.0 and Mozilla Firefox 53.0, the browser window(s) initiated by the WebDriver instance is bound to get destroyed (killed) once you invoke the quit() on the WebDriver instance.

So the blank window which you are seeing may be a result of either some other user interactions or a dangling instance.

Recommendation:

You can consider the following steps to start a clean Test Execution:

  1. Run CCleaner tool to wipe out all the leftovers from your previous executions.
  2. Restart your system to start your Test Execution on a clean OS environment.
  3. Keep the Test Environment isolated from other User Interactions.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352