selenium中driver.close()和driver.quit()哪个更彻底关闭浏览器?

2026-05-05 08:190阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计746个文字,预计阅读时间需要3分钟。

selenium中driver.close()和driver.quit()哪个更彻底关闭浏览器?

在Windows系统上,每次运行selenium程序后,chromedriver.exe进程总是无法正常关闭。查阅了相关文章后了解到,selenium操作Chrome浏览器需要ChromeDriver驱动来协助。

Windows系统上,每次运行完selenium程序后,chromedriver.exe进程总是不能彻底关闭。

网上参考了如下文章:www.jb51.net/article/201622.htm

selenium操作chrome浏览器需要有ChromeDriver驱动来协助。webdriver中关浏览器关闭有两个方法,一个叫quit,一个叫close。

/** * Close the current window, quitting the browser if it's the last window currently open. */ void close(); /** * Quits this driver, closing every associated window. */ void quit();

通过查看以上官方声明文档,可以看出close方法是关闭当前窗口,这个当前如何理解?就是driver实例操作的页面,叫当前。如果当前窗口只有一个tab,那么这个close方法就相当于关闭了浏览器。quit方法就是直接退出并关闭所有关联的tab窗口。所以,close方法一般关闭一个tab,quit方法才是我们认为的完全关闭浏览器方法。

阅读全文

本文共计746个文字,预计阅读时间需要3分钟。

selenium中driver.close()和driver.quit()哪个更彻底关闭浏览器?

在Windows系统上,每次运行selenium程序后,chromedriver.exe进程总是无法正常关闭。查阅了相关文章后了解到,selenium操作Chrome浏览器需要ChromeDriver驱动来协助。

Windows系统上,每次运行完selenium程序后,chromedriver.exe进程总是不能彻底关闭。

网上参考了如下文章:www.jb51.net/article/201622.htm

selenium操作chrome浏览器需要有ChromeDriver驱动来协助。webdriver中关浏览器关闭有两个方法,一个叫quit,一个叫close。

/** * Close the current window, quitting the browser if it's the last window currently open. */ void close(); /** * Quits this driver, closing every associated window. */ void quit();

通过查看以上官方声明文档,可以看出close方法是关闭当前窗口,这个当前如何理解?就是driver实例操作的页面,叫当前。如果当前窗口只有一个tab,那么这个close方法就相当于关闭了浏览器。quit方法就是直接退出并关闭所有关联的tab窗口。所以,close方法一般关闭一个tab,quit方法才是我们认为的完全关闭浏览器方法。

阅读全文