简体   繁体   中英

python selenium driver.quit() can not quit firefox browser if firefox_profile setted

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM