Page 1 of 1

Finishing list iteration before exception

Posted: Fri Feb 08, 2019 11:46 pm
by uilfut
Hi there

I'm trying to "try" clicking a number of URLs before refreshing the page and trying again.

But when the first one doesn't work, it will go straight to the "except" clause.

Is there a way to rewrite my loop so that it tries the whole list first, please?

(currently it will try value 12, then refresh and try value 12 again)

Code: Select all

 preferred_times = ['12', '13', '14']

        for pt in preferred_times:

            try:  
                find_element_by_xpath("//html/[1]/tbody/[" + pt + "]/td[2]/tfont").click()

            except:
                driver.refresh()

Re: Finishing list iteration before exception

Posted: Sat Feb 09, 2019 7:17 am
by paddyg
put pass in the except (really you should only pass for the specific exception not generally) then move driver.refresh() to after the for loop.

Re: Finishing list iteration before exception

Posted: Sat Feb 09, 2019 4:42 pm
by uilfut
Thank you!