Forum Discussion
Hi 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")
Hi rraghvani,
Based on your suggestion I've tweaked my code. I've removed Try and Except block and used the OnLogError event to handle the error. I've added a project variable to increase error count ( we can not reset Log.errCount value), based on this project variable value I'm making the decision to exit the loop or to enter another function in the loop. I'm resetting this project variable value at the start of every test case.
Thanks,
Diwakar
Related Content
- 4 years ago
- 9 months ago
- 8 years ago
- 3 years ago
Recent Discussions
- 17 hours ago