How To Handle Exceptions
Intro
It doesn't take long when using Selenium before you run into errors from Selenium that may seem inexplicable
(e.g., NoSuchElementError
or StaleElementReferenceError
). They can be a bit of a shock if you're not sure
what they are, how to handle them, or where to find documentation on how to address them.
A Solution
By adding some simple exception handling we can catch Selenium's errors and make our tests more resilient.
Let's take a look at an example.
About The Author
Dave Haeffner is the original writer of Elemental Selenium -- a free, once weekly Selenium tip newsletter that's read by thousands of testing professionals. He also created and maintains the-internet (an open-source web app that's perfect for writing automated tests against).
Dave has helped numerous companies successfully implement automated acceptance testing; including The Motley Fool, ManTech International, Sittercity, and Animoto. He is also an active member of the Selenium project and has spoken at numerous conferences and meetups around the world about automated acceptance testing.