I am using Python for Selenium RC and I am using the following selenium command:
self.se.get_attribute("CSS")
This command asserts when the respective CSS mentioned is not found on the webpage.
Is it possible for me to avoid the assert from happening and instead of the assert, another command is executed (On the condition that the assert has taken place)
self.se.get_text("another CSS")
Is there a way in python to capture the assert and just store its value and continue forward without terminating the program?
Could someone please help me with this?
Thanks
If when
'CSS'is not valid, selenium raises aTypeError, you can catch and handle the exception in atry..exceptblock:This is an example of the “Easier to ask forgiveness (EAFP) than permission” coding style. The alternative is the Look before you leap (LBYL) coding style (see Nikita Barsukov answer for example). Both are possible, though I think EAFP is preferred in Python because doesn’t clutter the code with conditionals which may or may not fully capture the exceptional condition. EAFP is also fast when the exception is not raised too often. If the exception is raised often, LBYL may be preferrable.