I'm having trouble getting my main method (or any method) to run after refreshing the page with Selenium Python. Everything including the refresh works fine, but how does one get the program to run upon refresh much like it would when first running the program from command prompt?
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome(executable_path=r'./chromedriver.exe', options=chrome_options)
driver.get('https://www.google.com')
wait = WebDriverWait(driver, 10)
button = wait.until(EC.element_to_be_clickable((By.XPATH, '//button[@data-a-target="XXXXX"]')))
def main():
try:
button.click()
(codeblock)
#refresh upon error detection
except Exception
driver.refresh()
#not sure what this does but it doesn't work without it
if __name__ == "__main__":
main()
Note this block is missing or has changed code ex. the URL. But everything including the refresh call upon an exception works fine.
I'm really not sure how this all fits together, as I need main() to be called after refresh, though there are variables declared outside of main() that main() uses. Unsure if that raises any issues.
In short, how might one be able to make what is effectively an infinite loop (assuming main() loops when no errors occur), in that when an error occurs, the page refreshes (check), and upon refresh goes back to main()?