Set-up
I have a list of urls which each contain a form. I use Selenium to fill the form and I loop over the urls. I.e.
for url in urls:
browser = webdriver.Chrome()
browser.implicitly_wait(30)
browser.get(url)
data = {} # dictionary containing variables to be inserted in the url's form
var1 = browser.find_element_by_id("id")
var1.clear()
var1.send_keys(data['var1'])
# here follow more variables to be inserted
where urls = [] # list containing all urls. This works fine.
Problem
Every now and then I receive an unexpected error for one of the urls. For example, the error results from that particular url not having a specific field.
I adjust the code to be able to handle all urls missing that specific field. Everything is fine.
But, I need to restart the loop from the beginning – not efficient.
Is there a way to tell Python to restart the loop from the url which resulted in an error, instead of from the first url in the list?
try except else?