捕获 HTML 标签属性作为 QTP 中的对象属性 [英] Capturing HTML tag properties as objecct properties in QTP

查看:33
本文介绍了捕获 HTML 标签属性作为 QTP 中的对象属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 HTML 标记,QTP 将其正确识别为 WebEdit 对象:

I have the following HTML tag, which QTP correctly identifies as a WebEdit object:

<input style="width: 228px;" aria-describedby="x-auto-0" _id="Tenant" name=""
tabindex="1" id="x-auto-23-input" class="x-form-field x-form-text x-form-invalid"
type="text">

如何将 HTML 标记中的 _id 属性转换为 QTP 中的对象属性?我使用对象标识对话框将 _idhtml _id 属性添加到 WebEdit 类.但是,当我使用 Object Spy 或 Recorder 时,两者都没有填写.

How do I get the _id property from the HTML tag into an object property in QTP? I've used the Object Identification dialog to add both _id and html _id properties to the WebEdit class. However neither are filled in when I use either the Object Spy or the Recorder.

请注意,被测试的页面包含许多这样的文本输入,每个输入都有一个空白的 name 但描述性的 _id.我正在尝试将 _id 放入 WebEdit 的属性中,以便我可以通过 Browser("Browser").Page("Page"),WebEdit("_id:=租户").

Note that the page being tested contains a number of these text inputs, each with a blank name but descriptive _id. I'm trying to get the _id into a property of WebEdit so I can refer to a particular text box by Browser("Browser").Page("Page"),WebEdit("_id:=Tenant").

推荐答案

可以使用 .Object.GetAttribute() 函数获取 HTML 属性.这对于获取非标准属性(即_id")特别有用.

HTML attributes can be obtained by using the .Object.GetAttribute() function. This is particularly useful for obtaining non-standard attributes (i.e., "_id").

属性id"与运行时对象属性html id"对齐,因此可以使用GetROProperty()或上述方法获取.

The attribute "id" aligns with the Runtime Object Property "html id", so that can be obtained using GetROProperty() or the above method.

使用这些方法的示例如下:

An example of using these methods is below:

Dim objUI    
Set objUI = Browser("Browser").Page("Page").WebEdit("WebEdit")
Print objUI.GetROProperty("html id")
Print objUI.Object.GetAttribute("id")
Print objUI.Object.GetAttribute("_id")
Set objUI = Nothing

要使用描述性编程来访问对象,您可以使用 attribute/ 表示法以及正则表达式.例如:

To use descriptive programming to access an object, you can use the attribute/ notation as well as regular expressions. For example:

Set objUI = Browser("Browser").Page("Page").WebEdit("attribute/_id:=Tenant", "html id:=x-auto-\d*-input")

默认情况下,调试查看器中的 Web 元素不会公开 .Object 方法和属性.可以通过注册 IE8 中包含的进程调试管理器 (PDM) 来增强 QTP 调试.这将帮助您通过使用 .Object 发现 QTP 中可用的其他属性和方法.有关在 QTP 11 中增强调试的更多信息,请参阅以下文章:http://northwaysolutions.com/blog/qtp-11-how-to-enable-enhanced-debugging-features/

By default, the .Object methods and properties are not exposed for web elements in the Debug Viewer. It is possible to enhance QTP debugging by registering the Process Debug Manager (PDM) which is included in IE8. This will help you discover additional properties and methods that are available in QTP by using .Object. For more information on enhancing debugging in QTP 11, please see the following article: http://northwaysolutions.com/blog/qtp-11-how-to-enable-enhanced-debugging-features/

这篇关于捕获 HTML 标签属性作为 QTP 中的对象属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆