19 HTML DOM
Concept: Document Object Model for HTML document.(Betterperformance then Test Object, DP)
The QTPpage Test Object’s “Object” property provides access to the HTML DOM:
e.g. Set oDocument =Browser(“”).Page(“”).Object
19.1 When use the HTML DOM
Canaccess object property but QTP not provide. E.g. individual radio buttonelement;
19.2 HTML DOM Objects
--the Document Object: represent entire document and it’s root node.
| ||
--the HTML Element Object: refer to any particular node in the DOM. | ||
--the HTML Element Collection: a collection of one or more elements. HTML:
QTP code:
|
19.3 How to get Document object:
'Method 1 Set Document = Browser("").Page("").Object 'Method 2 Set Document = Browser("").Object.document 'Method 3 Set Document = Browser("").Page("").Frame("").Object.document |
19.3 How to get web page Element using the DOM:
HTML:
QTP code:
|
19.4 Other HTML Elements
--Link/Button Document.Link(“name”).Click Document.Link(“id”).Click Document.getElementById("id").Click Document.getElementsByName("name")(0).Click | ||
--Text Box Document.getElementById("id").Value Document.getElementsByName("name")(0). Value ‘Or get all text box collection Set allElems = document.getElementsByTagName("Input") For Each elem in allElems elem.value = "Tarun" Next | ||
--Combo or ListBox (所有的选项是个整体)
| ||
--Checkbox Document.getElementsByName("name")(0).Checked = Ture | ||
--Radio button(所有的选项都是个体)
‘QTP Code:
| ||
--HTML TABLE *Cells provide the access to all the cells in table; * Rows provide the rows in table. Rows also provide a “cell” collection to access a specific cell present in a row.
|
19.5 Converting a DOM object to QTP Test Object
The HTML DOM sourceIndex property is the index value ofobject in DOM tree and can be used to get its corresponding QTP test object.
‘Use DOM to get index value Set oText = Document.getElementById("myTable") srcIndex = oText.sourceIndex
‘Code with index value and object type Set Document = Browser("Browser").Object.Document Set oText = Document.getElementById("firstname") srcIndex = oText.sourceIndex Browser("Browser").Page("Page").WebEdit("source_Index:=" & srcIndex ).Set "frank" ‘Or Browser("Browser").Page("Page").WebEdit("sourceIndex:=" & srcIndex ).Set "frank"
|
19.6 Checking appearance using Style sheet:
Access the style sheet using the currentStyle and Styleobjects of every element.
Set oWebElement = Browser("Browser").Page("Page").WebElement("html id:=checkHidden").Object print oWebElement.className |
Set oWebElement = Browser("Browser").Page("Page").WebElement("html id:=checkHidden").Object print oWebElement.currentStyle.dispay = "value" |
Note: for more currentStyle object and related method, ref msdn.microsoft.com
19.7 Selecting a Radio button by Text
Radio button in HTML are only associated with valueproperties and not with the text appearing with them.
思路:UsingDOM getAdjacentText method. 不做研究,需要时再说。