uilfut
Posts: 72
Joined: Sat Mar 03, 2018 1:20 am
Location: Toronto

Finishing list iteration before exception

Fri Feb 08, 2019 11:46 pm

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()

User avatar
paddyg
Posts: 2541
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Finishing list iteration before exception

Sat Feb 09, 2019 7:17 am

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.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

uilfut
Posts: 72
Joined: Sat Mar 03, 2018 1:20 am
Location: Toronto

Re: Finishing list iteration before exception

Sat Feb 09, 2019 4:42 pm

Thank you!

Return to “Python”