Forum Discussion

GAutomation's avatar
GAutomation
Frequent Contributor
6 years ago
Solved

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.

 

  • 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

2 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    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