WORKING WITH QTP

TestEveryThinG

How can I access HTML tags directly?

Posted by rajivkumarnandvani on June 3, 2010

QuickTest provides direct access to the browser’s Document Object Model
(DOM) through which you can access the HTML tags directly. Access to the
DOM is performed using the .Object notation.
The test below demonstrates how to iterate over all the tags in a page. The
test then outputs the inner-text of the tags (the text contained between the
tags) to the Test Results using the Reporter object.
‘ Use the on error because not all the elements have inner-text.

On Error Resume Next
Set Doc = Browser(“CNN Interactive”).Page(“CNN Interactive”).Object
‘ Loop through all the objects in the page.
For Each Element In Doc.all
TagName = Element.TagName ‘ Get the tag name.
InnerText = Element.innerText ‘ Get the inner text.
‘ Write the information to the test results.
Reporter.ReportEvent 0, TagName, InnerText
Next

One Response to “How can I access HTML tags directly?”

  1. Anonymous said

    Thank you very much 🙂 it saved me today

Leave a comment