CaptureText not working as expected on a HTMLDiv object in TestPartner

over 8 years ago

Trying to capture the text of a HMTLDiv object which is inside a HTMLBrowser object (the div is quite long, like a height of 10,000 rows). It appears that HTMLDiv ("name").CaptureText only captures the current position you are in. So if you have to scroll down then you need to be in position before you perform the CaptureText. It is also possible to use CaptureText(Left, Top, Width, Height).

So here are the issues:
1) if CaptureText is called at the HTMLDiv level, the following issues are seen:
      a) If you scroll down the page and then perform HTMLDiv("name").CaptureText then we are automatically placed to the beginning of the HTMLDiv object, therefore we only capture the first page.
      b) If you scroll down the page (or even if you do not) and then perform HTMLDiv("name").CaptureText(1,1,2000,2500), you still get the first page.
      c) The HTMLDiv is not scrollable, you must scroll at the Browser level.

If you scroll at the browser level you can capture text fine, you can position the scroll to where you would like and perform the CaptureText which captures the data of the current view without positioning back to the top of the HTMLDiv object.

The problem is that the CaptureText is capturing other information on the browser that are not needed, we want to capture the HTMLDiv data only.

Getting the children of the HTMLDiv with TestPartner returns zero items.
However, in TestPartner, the innerText property of the HTMLDiv object contains the data that you want to retreive.

The function below captures the innerText property and uses the Split method to split the captured data using a delimeter. The result is that the split string is then stored to a collection representing the same information we expected to capture of the data in the HTMLDiv object. See solution below containing generic function 'getItems' which takes a TObject as argument and delimeter, and returns a Collection object.

Sub Main()

      IEWindow("Application=IEXPLORE.EXE Caption='Test Page - Windows Internet Explorer'").Attach

      HTMLBrowser("Caption='Test Page' Index=2").Attach
      ' htmlDiv object
      Dim divObj As THTMLDiv
      Set divObj = HTMLDiv("ID=HTML_REPEATER_LiteServiceCatalogSearch")
      ' ordered set
      Dim cItems As New Collection
      Set cItems = getItems(divObj, "Qty")
      ' using the set we can manipulate the returned data
      Dim i As Integer
      For i = 1 To cItems.Count
            MsgBox cItems.Item(i), vbOKOnly, "Items"

End Sub

' function to get the text property of nested HTMLDiv
' data returned in an ordered set of items as a single Collection object

Public Function getItems(ByVal obj As TObject, ByVal delimeter As String) As Collection
      Dim CapturedText As String
      CapturedText = obj.InnerText

      Dim cItems As New Collection
      Dim StrSplit As Variant
      Dim nItems As Integer
      StrSplit = Split(CapturedText, delimeter)
      nItems = UBound(StrSplit) - LBound(StrSplit) - 1
      Dim i As Integer
      For i = 0 To nItems
            cItems.Add (StrSplit(i))
      Set getItems = cItems
End Function


Support Tip
Comment List
Related Discussions