Your question heading :
If we set a variable to “find an element”, what are all the possible
return values?
think about this as a positive and negative returns, that is :-
if found
, A web element will be returned.
if Not found
, there can be multiple exception raised such as NoSuchElement
, etc.
Now coming to assert part. First question that comes in my mind is, What is assert and Why do we need assert in automation
, I believe you've the same thinking here.
An assert is there to help you, by alerting you to errors that must
never occur in the first place, that must be fixed before the product
can be shipped. Errors that do not depend on user input, but on your
code doing what it is supposed to do.
reference of this can be found here
additionally they can be good
- Checks if a particular block of code is reachable or not.
- Checks if the assumptions made by the developer are correct.
- They can also check the state of an object.
and may be more..
Now, coming to actual question :-
assert button is not None, how could is not None be helpful?
May be it does not look helpful in this context.
But think, about a situation where a customer expect a table visibility, when they click on this button. and in production environment, due to some glitch it's not loading or showing any content, with the help of assertion you can print or show a message to the customer, or can handle an uncaught exception. I know they are other ways as well, but for me personally in automation if I have assertion at place, and if the condition is met or does not meet, I could see the exact execution status in my test report. So it's beneficial for debugging as well.