Forum Discussion

david_quick's avatar
david_quick
Occasional Contributor
12 years ago

Accessing the DOM

I'm attempting to access the DOM (see the object in the attached screenshot) but using the below script returns no items:




  Set page = Sys.Browser("iexplore").Page("*")


    


  Set objError1 = page.contentDocument.getElementsByTagName("gritter-item")


  Set objError2 = page.contentDocument.getElementsByClassName("gritter-item")


  Set objError3 = page.contentDocument.getElementsByTagName("gritter-title")


  Set objError4 = page.contentDocument.getElementsByClassName("gritter-title")



I can access the object using FindAllChildren but I have to build a delay into the script to give the error message time to display on screen:




  delay (500)


  arrProperties = Array("ObjectType","contentText")


  arrValues = Array("Panel","*JavaScript Error*")    


  arrObjects =  Sys.Browser().Page("*").FindAllChildren(arrProperties, arrValues,20000)



Can anyone help?


  • david_quick's avatar
    david_quick
    Occasional Contributor
    Using an XPath to find the object solved my issue:




      Set Page = Sys.Browser("iexplore").Page("*")


      'Page.Wait()


      


      arr = page.EvaluateXPath("//div[@id='gritter-notice-wrapper']")


      


        ' If an error is displayed log the text


      If Not IsNull(arr) Then


        For i = 0 To UBound(arr)


            Log.Message(arr(i).contentText)


            blnError = True


        Next


      End If

  • david_quick's avatar
    david_quick
    Occasional Contributor
    Ok getting somewhere.  Because the name and tag properties are not set, using getElementById gets the object:



      Set objError = page.contentDocument.getElementById("gritter-item-1")



    The problem now is how do I manage the scenario where the object does not exist?