2

I have studied selenium exceptions, but they aren't really used in my company. I want to ask:

  1. Is it true that they are sort of independent of Selenium, since they are inherited from Exception class and they are only used with Selenium?

  2. Is it true that they are seldomly used because there are other ways to handle the same situation with isEnabled (), isDisplayed() and isSelected() methods?

  • You can't avoid handling the exceptions that selenium throws (unless you just let your tests fail), so I assume you mean you try to avoid relying on exceptions to catch failure cases if there is an alternative. Is that correct? – Mark Lapierre Mar 11 '17 at 4:50
2

Is it true that they are sort of independent of Selenium, since they are inherited from Exception class and they are only used with Selenium?

In general, yes, exceptions are sub classes of more generic exception parent class. But they can be used anywhere not just in Selenium.

Is it true that they are seldom used because there are other ways to handle the same situation with isEnabled (), isDisplayed() and isSelected() methods?

Not necessarily. Exceptions are written to handle unexpected (or expected, depends on how well you are prepared) conditions / results. Although Selenium provides you with an arsenal of assertion methods as you mentioned, sooner or later, you will still need to customize your own exceptions as there will be a unique situation that forces you to write your own exception.

In summary, I do not really know your company does not use exceptions; it is almost impossible to write well-behaved code without them. Exceptions are your friends, you will love them after you get to know them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.