preload

How to retrieve value from text node div/span/p (TestComplete)

Posted by Albert Gareev on Nov 24, 2012 | Categories: How toSource code

Description

Let’s say we need to retrieve a number of megabytes from under “Lots of space” category.

First, we need to explore the GUI implementation. If we’re lucky, this text node may have a unique class or ID value. Then it becomes a one-step search as in the code example below.

However, if the text node doesn’t have distinct identification properties we have to locate it through one of parents/grandparents that can be identified reliably. Then in the context of the parent we can locate the target text and extract it.

Implementation

  Dim PropNames, PropValues, IEProcess
  Dim objSpan1, objParent

  'Before running this code example make sure Google Mail Login page is up in IE

  PropNames = Array("processname", "index")
  PropValues = Array("iexplore", 1)
  Set IEProcess = Sys.FindChild(PropNames, PropValues, 1, True)
  If Not IEProcess.Exists Then
    'not found - exit
  End If

  '1 - Locating span by html ID
  PropNames = Array("ObjectType", "idStr")
  PropValues = Array("TextNode", "quota")
  Set objSpan1 = IEProcess.FindChild(PropNames, PropValues, 100, True)
  MsgBox objSpan1.contentText

  '2 - Locating span via parent object
  'Get parent
  PropNames = Array("ObjectType", "tagName", "className")
  PropValues = Array("Panel", "div", "product-info mail")
  Set objParent = IEProcess.FindChild(PropNames, PropValues, 100, True)
  'Get paragraph in parent
  PropNames = Array("tagName", "contentText")
  PropValues = Array("P", "*megabytes*")
  Set objSpan1 = objParent.FindChild(PropNames, PropValues, 100, True)
  'Little parsing to retrieve the number
  MsgBox Mid(Left(objSpan1.contentText, InStr(objSpan1.contentText, "megabytes")-1), 5)


Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.