Python Selenium: How to check whether the WebDriver did quit()?

前端 未结 7 980
一个人的身影
一个人的身影 2021-02-08 12:26

I want to control whether my WebDriver quit but I can\'t find a method for that. (It seems that in Java there\'s a way to do it)

from selenium impor         


        
7条回答
  •  情深已故
    2021-02-08 13:08

    ''''python def closedriver(): global drivername drivername.quit() global driveron driveron=False '''' this function "closedriver" uses a global variable named "drivername" and global bool variable named "driveron",you may just pass a current driver as parameter but
    NOTE: driveron must be global to store the state of driver being 'on' or 'off'. ''''python
    def closedriver(drivername):
    global driveron
    try:
    drivername.quit()
    except:
    pass
    driveron=False
    ''''
    and when you start a new driver, just use a check
    global driveron
    if not driveron:
    driver=webdriver.Chrome()

提交回复
热议问题