cancel
Showing results for 
Search instead for 
Did you mean: 

when it is not able to find an object it is not returning correct value

SOLVED
GAutomation
Frequent Contributor

when it is not able to find an object it is not returning correct value

function click_btn(window,propertyname)

set currentObj = findObject(propertyname)

if (isobject(currentObj ) then

currentObj.click

log.Message("button is exist")

 

else

log.Message("button does not  exist")

 

------------------------------------------

function findObject(propertyname)

found = false

set setobj = utils.CreateStubObject

 

if propertyname =undefined then

found =false

e;se

set name1 = windows.Find("Name",propertyname,10)

if name.Exists then

found = true

set setObj = name

else

found =false

end if

if (found = True) and isObject(setObj) then

set findObject = setObj

else

findObject =false

end if

end function

 

if it able to find the objects the code works fime and returns correct message but if its not able to find objects it is not returning " log.Message("button does not exist exist")

basically if found is true it sets findobject correctly.if its false it is not setting findObject

in log getting object required(findobject)

 

not sure where ima going wrong.

 

1 ACCEPTED SOLUTION

Accepted Solutions
tristaanogre
Community Hero

Re: when it is not able to find an object it is not returning correct value

Your problem is in your findObject.  If it doesn't find the object, then found = false and "false" is not an object.

 

I think this is a better, more elegant way of doing the same thing... fewer variables and a more direct result.

 

function findObject(propertyname)

if propertyname <> undefined then

set name = windows.Find("Name",propertyname,10)

end if

if name.Exists then

set findObject = name

else

set findObject = Utils.CreateStubObject

end if

end function

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

2 REPLIES 2
tristaanogre
Community Hero

Re: when it is not able to find an object it is not returning correct value

Your problem is in your findObject.  If it doesn't find the object, then found = false and "false" is not an object.

 

I think this is a better, more elegant way of doing the same thing... fewer variables and a more direct result.

 

function findObject(propertyname)

if propertyname <> undefined then

set name = windows.Find("Name",propertyname,10)

end if

if name.Exists then

set findObject = name

else

set findObject = Utils.CreateStubObject

end if

end function

Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

GAutomation
Frequent Contributor

Re: when it is not able to find an object it is not returning correct value

Thnaks Robert.

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors