Forum Discussion

ArmandsBruns's avatar
ArmandsBruns
Frequent Contributor
12 years ago

EvaluateXPath

Hi,



Maybe someone knows if the object exists then everything works, but if the object doesn't exist then displays the following error:

"
Microsoft VBScript runtime error

Type mismatch: 'UBound''"



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



Function EvaluateXPath_object(page, location, typeID, name)



  EvaluateXPath_object = False



  Dim Attr

  Set Attr = Log.CreateNewAttributes

  Attr.Bold = True



  Dim object, arr

 

  Sys.Refresh()

 

  Do

    counter = counter + 1

    

    Sys.Refresh()

 

    object = location.FindAllChildren(typeID,name,20000, True)

    arr = page.EvaluateXPath("(//*[text()='"+name+"'])")

      

      If UBound(arr) >= 0 Then

        Set button = arr(0)

        EvaluateXPath_object = True

        log.Message "Click - '"+name+"'",,, Attr

        button.Click

        page.Wait

      Else

        EvaluateXPath_object = False

        aqUtils.Delay(3000)

        Sys.Refresh()

        Log.Message("Doesn't find - '"+name+"'")

      End if

 

  Loop Until EvaluateXPath_object = True or counter > 25

    

End Function



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



Regards



Armands

2 Replies

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Armands,


     


    The EvaluateXPath method returns null when elements are not found. So, you'd better check whether the array contains the search results in the following way:


    If Not IsNull(arr) Then


    ...

  • ArmandsBruns's avatar
    ArmandsBruns
    Frequent Contributor
    Hi Tanya



    Thanks for your response



    Now work

    Solution:



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



    Function EvaluateXPath_object(page, location, typeID, name)



      EvaluateXPath_object = False



      Dim Attr

      Set Attr = Log.CreateNewAttributes

      Attr.Bold = True



      Dim object, arr, Counter

     

      Sys.Refresh()

     

      Counter = 0



      Do

        counter = counter + 1

        

        Sys.Refresh()

     

        object = location.FindAllChildren(typeID,name,20000, True)

        arr = page.EvaluateXPath("(//*[text()='"+name+"'])")

          

          If IsEmpty(arr) or IsNull(arr) Then

            EvaluateXPath_object = False

            aqUtils.Delay(3000)

            Sys.Refresh()

            Log.Message("Doesn't find - '"+name+"'")

          Else

              If UBound(arr) >=0 and arr(0).VisibleOnScreen = True Then

              Set button = arr(0)

              EvaluateXPath_object = True

              Log.Message "Click - '"+name+"'",,, Attr

              cels.Click

              Call Saglaba_Bildi(name)

              Call page.Wait

            Else

              EvaluateXPath_object = False

              aqUtils.Delay(3000)

              Sys.Refresh()

              Log.Message("Doesn't find - '"+name+"'")

            End if

          End if

     

      Loop Until EvaluateXPath_object = True or counter > 25

        

    End Function



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



    Regards



    Armands