简体   繁体   English

如果设置了firefox_profile,则python selenium driver.quit()无法退出firefox浏览器

[英]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. 我正在使用python selenium做一些自动工作。 After the work done, i need to close browser(I must use firefox). 完成工作后,我需要关闭浏览器(我必须使用Firefox)。 And I know driver.close() is to close current window and driver.quit() will close all windows and exit browser. 我知道driver.close()将关闭当前窗口,而driver.quit()将关闭所有窗口并退出浏览器。 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. 问题是:如果我使用python file.py来运行代码,则对我不起作用,但是如果我在python控制台中设置了驱动程序,则对我不起作用,这里的工作是说它只是关闭了我的网址,但是firefox浏览器无法退出。 All above tests have setted firefox_profile. 以上所有测试均设置了firefox_profile。 More, i found if i don't set firefox_profile the first way to run my code also working. 更多,我发现如果我没有将firefox_profile设置为运行我的代码的第一种方法也可以正常工作。 I think maybe it's a bug for firefox_profile. 我认为这可能是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 python 3.5.3
  • selenium 3.4.3 硒3.4.3
  • firefox 55.0.1 Firefox 55.0.1
  • geckodriver 0.18.0 壁虎起子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. 当我们使用带有最新GeckoDriver v.0.18.0Mozilla Firefox 53.0 Selenium 3.5.0 ,一旦在WebDriver上调用quit() ,则由WebDriver实例启动的浏览器窗口必定会被破坏(杀死)。实例。

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. 运行CCleaner工具以清除以前执行中的所有剩余。
  2. Restart your system to start your Test Execution on a clean OS environment. 重新启动系统以在干净的OS环境上启动Test Execution
  3. Keep the Test Environment isolated from other User Interactions . 保持Test Environment与其他User Interactions隔离。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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