Forum Discussion
rraghvani
Champion Level 3
3 years agoHi diwakar_sh12, not sure if you saw my previous response, but FindElement() does not throw an error. It either returns the Object or None. You need to raise an exception if the object is not found, for the try...except statement to work
For example, in the following code, Log.Message("Error") will never been called if FindElement() returns None
def test1():
obj = None
try:
obj = Sys.Browser("chrome").Page("*").FindElement("//a[@title='Contact Me']")
except:
Log.Message("Error") # Never called!
Log.Message("Continue...")
You need to do something like this
def test1():
try:
DoSomething()
except Exception as ex:
Log.Message(ex)
def DoSomething():
obj = None
obj = Sys.Browser("chrome").Page("*").FindElement("//a[@title='Contact Me']")
if obj is None:
raise Exception("Object not found")