selenium使用chrome驱动,关闭页面后进程还存在

在工作中,我需要用到selenium进行登录,偶然发现进程中有很多chrome浏览器的进程

类似这样几个月前的快要上百条,包括了chromedriver(浏览器驱动),还有browser(浏览器)虽然CPU和内存的使用可以忽略不计,但是这么挂着也相当辣眼睛。

错误定位比较快,看了一下webdriver.close()的源码,发现还有个.quit()方法:

    def close(self):
        """
        Closes the current window.

        :Usage:
            driver.close()
        """
        self.execute(Command.CLOSE)

    def quit(self):
        """
        Quits the driver and closes every associated window.

        :Usage:
            driver.quit()
        """
        try:
            self.execute(Command.QUIT)
        finally:
            self.stop_client()

close()的注释:关闭当前窗口;

quit()的注释:停掉驱动并关闭每一个相关的页面。

相当于这个意思:

蓝色是close,红色是quit。

问题解决。✅

猜你喜欢

转载自blog.csdn.net/zmy941110/article/details/89960757