Quicktest Pro - 匹配文本后找到第一个按钮
我想使用动态对象识别(描述性编程)来查找在某些给定文本之后出现的第一个标记为“删除”的按钮(例如,在文本“Item XYZ-123”之后出现的第一个删除按钮)。 如果文本和按钮都在网络表的一行内,我有一种笨拙的方法来做到这一点,但我希望有一个更优雅或更可靠的解决方案(希望是一个不依赖于表格的解决方案)。
我宁愿避免使用 .Object 属性,因为文档声称 .Object 属性仅在您在 IE 中测试时返回 DOM 对象,而不是在 Firefox 中。
谢谢!
I want to use dynamic object recognition (descriptive programming) to find the first button labeled "Delete" that occurs after some given text (eg, the first Delete button that appears after the text "Item XYZ-123"). I have a kludgy way to do it if both the text and the button are inside a single row of a webtable, but I was hoping for a more elegant or reliable solution (hopefully one that won't rely on tables).
I would prefer to avoid using the .Object property, since the documentation claims that the .Object property only returns DOM objects when you are testing within IE, and not within firefox.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设没有更简单的方法,您可以尝试解析 HTML。 在 HTML 中找到搜索文本,然后从该位置开始在 HTML 中搜索“删除”按钮。 您应该能够从 HTML 中提取 id 或其他一些标识属性,以用于描述性编程。
您是否有示例 HTML 和 QTP 代码供我们查看以了解更多详细信息? 也许有更简单的方法。
Assuming there is not an easier way to do it, you could try parsing the HTML. Find the search text in the HTML, and start searching the HTML from that point onward for a "Delete" button. You should be able to pull an id or some other identifying property from the HTML that you can use for the descriptive programming.
Do you have sample HTML and QTP code that we could look at to see more details? Perhaps there is an easier way.
让我先重新表述一下这个问题。
如果行号未知但您有唯一的键值来查找该行,如何检索对 WebTable 中包含的对象的引用?
这适用于按钮、复选框、组合框和表中的任何其他对象。
执行。
1) 查找行
intRow = objWebTable.GetRowWithCellText(sKeyValueText, "Item")
您可以按名称或编号指定列
2) 检索子对象
Set objButton = objWebTable.ChildItem(intRow, intCol, "WebButton", 0)
您只能按数字指定列。 如果同一单元格中有多个按钮,则最后一个参数将生效。
查看我的博客 (http://automationbeyond.wordpress.com/) 中的一些其他技术示例。
Let me rephrase the question first.
How to retrieve reference to an object contained within WebTable if row number is unknown but you have a unique key value to find the row?
That applies to buttons, checkboxes, comboboxes and any other object in table.
Implementation.
1) Find row
intRow = objWebTable.GetRowWithCellText(sKeyValueText, "Item")
You can specify column by name or number
2) Retreive child object
Set objButton = objWebTable.ChildItem(intRow, intCol, "WebButton", 0)
You can specify column by number only. The last parameter comes into effect if you have more than one button at the same cell.
Check some other technical examples in my blog (http://automationbeyond.wordpress.com/).
这是使用
sourceIndex
属性的解决方案,请注意,sourceIndex
是仅 IE 的属性,但 QTP 在 Firefox 上模拟它,因此相同的脚本可以在两种浏览器上运行。 如果source_index
不符合要求,您可以选择使用基于坐标的属性,例如abs_x
和abs_y
。下面的代码回答了所提出的问题,将其变成一个通用函数,作为读者的练习;o)
关于此解决方案的注意事项:
.*
和/或添加“html 标记”以获得更好的性能。BODY
等。ChildObject
会过滤掉WebElement
,认为它们不感兴趣。Here's a solution that uses the
sourceIndex
attribute, note thatsourceIndex
is an IE only property but QTP simulates it on Firefox so the same script will work on both browsers. You can choose to use coordinate based properties likeabs_x
andabs_y
ifsource_index
doesn't fit the bill.The code that follows answers the question as asked, making it into a general function is left as an exercise for the reader ;o)
Things to note about this solution:
.*
s and/or add an "html tag" for much better performance.BODY
etc.ChildObject
filters outWebElement
s assuming that they are un-interesting.