The HTML DOM defines a standard way for accessing and manipulating HTML documents.
HTML DOM定义了一种访问和控制HTML文档的标准方法。
All nodes can be accessed through the tree. Their contents can be modified or deleted, and new elements can be created.
所有节点能通过树访问。节点可以被修改或删除,也可以建立新的元素。
这是w3上的描述。我们在测试时遇到过这样的问题,一类信息在一个div下,而随着页面信息的变化,当初用object repository抓的table表对象属性发生变化而报错,信息没有取出来。比如电话号码,001-0033-3242,默认抓的是3个表格对象,页面表格index属性变化时出错。但发现它们在某一个特定的div下,比如名字叫divFamilyTelphone,开发的同事一般都这么设计页面信息显示的。
当时想到用程序通过div id取,想到树形结构,于是做出下面的函数,属于递归调用,拿出来分享一下。
当然了,根据的还是w3上dom的定义。
The nodeType property returns the type of node. nodeType is read only.
节点类型属性返回节点的类型,此属性为只读。
The most important node types are:
最重要的节点类型为:
Element type NodeType
Element 1
Attribute 2
Text 3
Comment 8
Document 9
这样的话,在qtp里做了如下函数:
1,主调用,返回结果,由qtp的封装方法取得节点做参数调用。
Function getMessageByDivId(strDivId)
'If the div not found
On error resume next
Set nodea = Browser("***").Page("***").Object.getElementById(strDivId)
If Err.number <> 0 Then getMessageByDivId = "" : Exit Function
Dim strReuslt
IterateNode nodea, strReuslt
getMessageByDivId = strReuslt
End Function
2.递归,根据dom节点属性的定义。文本节点返回。
Function IterateNode(strNodeName, byref strReturn)
'If is a text node, get value.
If strNodeName.nodeType = 3 Then
atext = strNodeName.nodeValue
strReturn = strReturn & atext
Exit Function
End If
'For iteration.
Set childNod = strNodeName.childNodes
If Not IsEmpty(childNod) and childNod.length <> 0 Then
For i = 0 to childNod.length - 1
IterateNode childNod(i), strReturn
Next
End If
End Function
其实后来想直接qtp的描述一样能实现,在对象库里定义element的属性,然后去运行时的文本值亦可实现。本人没有尝试,大家可以自己试试。
分享到:
相关推荐
The W3C DOM Core interfaces defines a minimal set of: A. interfaces for accessing and manipulating document objects B. Java object implementations for use with XML parsers. C. Conventions and ...
描述: "This document defines the LPDDR4 standard, This document defines the LPDDR4 standard." 此描述强调了文档的中心主题是LPDDR4标准的定义。LPDDR4作为移动设备内存技术的最新发展,代表了内存技术在能效和...
Defines the Java API for XML Processing (JAXP), the Streaming API for XML (StAX), the Simple API for XML (SAX), and the W3C Document Object Model (DOM) API. java.xml.bind Defines the Java ...
17.C++不仅仅是支持面向对象的程序设计语言; 18.学习编程最好的方法之一就是阅读源代码; 19.在任何时刻都不要认为自己手中... ... 20.请阅读《The Standard C++ Bible》(中文版:标准C++宝典),掌握C++标准;
org.dom4j Defines the XML Document Object Model in Java interfaces together with some helper classes. org.dom4j.bean An implementation of the dom4j API which allows JavaBeans to be used to store and ...
the usage of manufacturer independent tools, this document defines a standardised file format – called Electronic Data Sheet. Furthermore some derived file formats are specified. The Device ...
本文将基于《This document defines the DDR4 SDRAM specification》这一文档,深入解析DDR4 SDRAM规范的关键内容和技术特点。 #### 二、DDR4 SDRAM规范概述 DDR4 SDRAM规范是由JEDEC(Joint Electron Device ...
javax.jms The Java Message Service (JMS) API provides a common way for Java programs to create, send, receive and read an enterprise messaging system's messages. javax.jws javax.jws.soap javax.mail...
Merging the base Verilog language and the SystemVerilog extensions into a single standard provides users with all information regarding syntax and semantics in a single document. 该标准代表了先前两...
This document defines a level of standardization in the implementation of the digital pulse scheme for reporting sensor information via Single Edge Nibble Transmission (SENT) encoding. This standard ...
also defines a portion of the requirements that a laboratory must satisfy to qualify for and maintain CTIA Authorized Testing Laboratory (CATL) status (contact the CTIA Certification Program staff ...
This chapter defines some key terms for the remaining chapters. JDBC is a platform-independent interface between relational databases and Java. In today’s Java world, JDBC is a standard application ...
1.2 Purpose and Scope The purpose of this document is to provide recommendations for using ... Appendix A defines acronyms and abbreviations for the document. Appendix B lists related resources.
The uEFI replaces the BIOS and defines a standard interface among the operating system platform firmware, and external devices. • VPD settings on IMM-based servers • iSCSI boot settings. To modify ...
Here, the standard details the specific services and protocols required for diagnostic communication between a tester and a vehicle's electronic control units (ECUs). Key points covered in this ...
Within UML, OCL is the standard for specifying expressions that add vital information to object-oriented models and other object-modeling artifacts. Model-Driven Architecture (MDA) relies on OCL to ...
org.hibernate.metadata This package defines an API for accessing the Hibernate runtime metamodel. org.hibernate.stat This package exposes statistics about a running Hibernate instance to the ...
The primary goal of this standard is to establish a uniform framework for conducting emissions-related diagnostics, thereby facilitating consistent and accurate testing across different vehicle ...
org.hibernate.metadata This package defines an API for accessing the Hibernate runtime metamodel. org.hibernate.stat This package exposes statistics about a running Hibernate instance to the ...