Forum Discussion
rraghvani
Champion Level 3
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")
diwakar_sh12
3 years agoOccasional Contributor
Thanks, rraghvani for your input, I missed your earlier comment. You have suggested a good point here, let me try and come back to you on this.
Thanks,
Diwakar
Related Content
- 4 years ago
- 9 months ago
- 8 years ago
- 3 years ago
Recent Discussions
- 15 hours ago