Python Selenium-OSError:[WinError 6]句柄无效

Python Selenium-OSError:[WinError 6]句柄无效,python,python-3.x,selenium-chromedriver,Python,Python 3.x,Selenium Chromedriver,我试图保持我的自动chrome窗口打开,但它们关闭时出现以下错误: Traceback (most recent call last): File "C:\Users\Duma\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 841, in __del__ self._internal_poll(_deadstate=_maxsize) File "C:\Users\Duma\AppData\L

我试图保持我的自动chrome窗口打开,但它们关闭时出现以下错误:

Traceback (most recent call last):
  File "C:\Users\Duma\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 841, in __del__
    self._internal_poll(_deadstate=_maxsize)
  File "C:\Users\Duma\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1193, in _internal_poll
    if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0:
OSError: [WinError 6] The handle is invalid
使用Selenium和我的Python脚本如下所示:

login_url='https://www.life4laptop.com/index.php?route=account/login'
url='https://www.life4laptop.com/index.php?route=product/search&search=samsung'
list=[]
driver=webdriver.Chrome(crm_path, chrome_options=options)
driver.get(login_url)
elem = driver.find_element_by_id("input-email")
elem.clear()
elem.send_keys(x['life4laptop']['username'])
elem = driver.find_element_by_id("input-password")
elem.clear()
elem.send_keys(x['life4laptop']['password'])
elem = driver.find_element_by_xpath("//form/input[@type='submit']")
elem.click()
driver.get(url)

driver2=webdriver.Chrome(crm_path, chrome_options=options)
driver2.get(login_url)
elem = driver2.find_element_by_id("input-email")
elem.clear()
elem.send_keys(x['life4laptop']['username'])
elem = driver2.find_element_by_id("input-password")
elem.clear()
elem.send_keys(x['life4laptop']['password'])
elem = driver2.find_element_by_xpath("//form/input[@type='submit']")
elem.click()
driver2.get(url)
#driver.close()
#driver.quit()

任何线索为什么,以及如何让它工作?

可能是因为我退出了脚本。当脚本在有争议的情况下运行时,一切正常。

如果您来到这里想知道为什么在
tearDown(self)
方法上会出现此错误,可能是因为您使用的是
driver.close()
而不是
driver.quit()

您可以参考此线程()来解释两者之间的区别,但总结起来:
driver.close()
关闭选项卡/窗口,但不关闭驱动程序实例,而
driver.quit()关闭后者

希望它能帮助其他人在这里寻找这个问题的答案