I'm writing a python script that uses Firefox webdriver. However, the browser instance should not be created until a condition is met.
When testing if browser is already opened, there is a message in Spyder's editor: undefined name 'driver'.
How to change the code to get rid of that message?
while True
    if time_to_work():
        if driver.service.is_connectable():            
            do_something()
        else:
            driver = webdriver.Firefox(profile, options=options)
            print('Browser started..')
    else:
        if driver.service.is_connectable():
            print('Closing browser..')        
            driver.quit()