关闭驱动程序后终止 python 脚本? (硒,python)

Kill python script after driver is closed ? (Selenium, python)

关闭驱动程序后终止 python 脚本? (硒,python) 因此,如果用户关闭 chrome 驱动程序,脚本也会关闭。 真的就这些了,在 google 上搜索了一段时间,没有找到任何东西。提前谢谢你

你应该提供一些代码来帮助我们,但是 chrome 驱动程序无论如何都离脚本很近,假设你正在使用 Selenium 进行测试,你可以使用 TearDown method 例如:

def tearDownClass(cls):
        super().tearDownClass()
        cls.browser.quit()
try:
    options = webdriver.ChromeOptions()
       
    browser.implicitly_wait(10)
    browser.get(url)
    #more code

except Exception as e:

    if "not reachable" in str(e):
        print("Chrome crashed :" + str(e))
        sys.exit()
    else:
        print("Some Other Exception was thrown: " + str(e))
        raise Exception(str(e))

只捕获异常并使用sys.exit()

这将为 chrome 关闭正常退出脚本,对于所有其他它将抛出该异常