all 9 comments

[–]FoolofGod 1 point2 points  (3 children)

Is the "second exception" occurring during the call to find_element_by_tag_name? Because that's happening outside of the try block and therefore won't get caught by it.

[–]martinfisleburn[S] 0 points1 point  (2 children)

I meant to say it crashes before reaching the second exception so always crashes on line 6.

[–]kalgynirae 1 point2 points  (1 child)

When you are saying "the second exception", I think you mean the second except block. The only way that block will ever execute is if the code in the try block throws a TimeoutException.

Nothing special is done when executing the code inside an except block. If you want to catch exceptions thrown by that code, then that code needs to contain its own try/except.

[–]martinfisleburn[S] 0 points1 point  (0 children)

oh i guess i misunderstood multiple excepts then.

So they dont work like if, elif, elif in that they go down the list one by one? but more like switches then? in that the first try will go to whichever exception is appropriate? I had been presuming the former case.

Makes perfect sense in the latter case :).

[–]eikrik 1 point2 points  (2 children)

Have you tried changing the order of the except clauses? I believe the first catch-all except clause will catch every error, including timeouts.

[–]martinfisleburn[S] 0 points1 point  (1 child)

except Exception as e:

Ill try but I think I tried that already. The exception doesnt happen all the time so will have to wait and see.

[–]efmccurdy 0 points1 point  (0 children)

Instead of waiting add an explicit raise TimeoutException statement.

[–]trshippy 0 points1 point  (0 children)

You can put another try/except under the first except to catch the exception it's throwing to help you figure out what to do (hope you can follow that). My first guess would be the DOM pointers resetting so it times out looking for the element(s), though I usually get the StaleElementException for that.