Quicktest Pro - 匹配文本后找到第一个按钮

发布于 2024-07-22 05:46:32 字数 259 浏览 8 评论 0原文

我想使用动态对象识别(描述性编程)来查找在某些给定文本之后出现的第一个标记为“删除”的按钮(例如,在文本“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓝海 2024-07-29 05:46:33

假设没有更简单的方法,您可以尝试解析 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.

音盲 2024-07-29 05:46:33

让我先重新表述一下这个问题。

如果行号未知但您有唯一的键值来查找该行,如何检索对 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/).

递刀给你 2024-07-29 05:46:32

这是使用 sourceIndex 属性的解决方案,请注意,sourceIndex 是仅 IE 的属性,但 QTP 在 Firefox 上模拟它,因此相同的脚本可以在两种浏览器上运行。 如果 source_index 不符合要求,您可以选择使用基于坐标的属性,例如 abs_xabs_y

下面的代码回答了所提出的问题,将其变成一个通用函数,作为读者的练习;o)

''#1. Create description for locator text 
Set textD = Description.Create()
textD("micclass").Value = "WebElement"
textD("innertext").Value = ".*Item XYZ-123.*"

''#2. Find locator sourceIndex
set texts = Browser("B").Page("P").ChildObjects(textD)
Set text = texts(texts.Count-1) ' Take last text '
textIdx = text.GetROProperty("source_index") ' works for FF too '

''#3. Create description for button 
Set buttonD = Description.Create()
buttonD("micclass").Value = "WebButton"
buttonD("value").Value = "Delete"
Set btns = Browser("B").Page("P").ChildObjects(buttonD)

''#4. Find first button after locator text 
For i = 0 To btns.Count
    If btns(i).GetROProperty("source_index") > textIdx Then
        btns(i).Click ' Or whatever you want to do with it '
        Exit For
    End If
Next

关于此解决方案的注意事项:

  • 它不假设有关元素的任何信息包含文本,如果您知道这是元素中的整个文本,您可以删除 .* 和/或添加“html 标记”以获得更好的性能。
    • 这就是为什么我们采用符合描述的最后一个元素,第一个元素将是 BODY 等。
  • 在文本描述中,我们必须指定“micclass”=“WebElement”,因为默认情况下ChildObject 会过滤掉 WebElement,认为它们不感兴趣。

Here's a solution that uses the sourceIndex attribute, note that sourceIndex 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 like abs_x and abs_y if source_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)

''#1. Create description for locator text 
Set textD = Description.Create()
textD("micclass").Value = "WebElement"
textD("innertext").Value = ".*Item XYZ-123.*"

''#2. Find locator sourceIndex
set texts = Browser("B").Page("P").ChildObjects(textD)
Set text = texts(texts.Count-1) ' Take last text '
textIdx = text.GetROProperty("source_index") ' works for FF too '

''#3. Create description for button 
Set buttonD = Description.Create()
buttonD("micclass").Value = "WebButton"
buttonD("value").Value = "Delete"
Set btns = Browser("B").Page("P").ChildObjects(buttonD)

''#4. Find first button after locator text 
For i = 0 To btns.Count
    If btns(i).GetROProperty("source_index") > textIdx Then
        btns(i).Click ' Or whatever you want to do with it '
        Exit For
    End If
Next

Things to note about this solution:

  • It doesn't assume anything about the element containing the text, if you know that this is the entire text in the element you can remove the .*s and/or add an "html tag" for much better performance.
    • That's why we take the last element that fits the description, the first element will be the BODY etc.
  • In the text's description we have to specify "micclass" = "WebElement" because by default ChildObject filters out WebElements assuming that they are un-interesting.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文