I have a been having a problem with using selenium in my python code as the program keeps crashing. I have tried to use try, except statement to catch the error so that when it crashes I can still close it successfully but I have not been able to get it to work as the driver needs to be declared before it the exception statement Please how can I catch the crash and close it. This is what I have tried
try:
driver = webdriver.Chrome(chrome_options=chrome_options)
except Exception as e:
driver.close()
driver.quit()
It insist that driver does not exists and if I declare the driver before the exception statement with no argument it gives error although I am using Chrome in this example but I intend to use it for firefox as well
Thanks