RFT Html.Select 具有动态 ID,无法识别

RFT Html.Select has dynamic id and is not recognized

记录的行是 list_prmT_SV_N18947080x18A5068().click(atText("Claimed Students"));

我试图让它发挥作用的是:

ClickDropdown("Claimed Students");


public static void ClickDropdown(String name)
{
    GuiTestObject textObj = findTextObject(name);
    if (textObj != null) {
        textObj.click();
    } else {
        throw new ObjectNotFoundException();
    }
}


 private static GuiTestObject findTextObject(String name)
 {
     TestObject[] tobs = find(atDescendant(".class", "Html.SELECT", ".value", name ), true);
     if(tobs.length == 0)
         return null;
     return (GuiTestObject)tobs[0];
 }

可用的属性有 .id(dynamic)、.text、.class

您在问题中描述的问题是一个常见问题,主要与使用 JQuery.

构建的 HTML 个应用程序有关

使用find方法是正确的方法,因为您可以抽象RFT使用的识别属性。查看您的 findTextObject 我建议您修改 find 调用如下:

find(atDescendant(".class", "Html.SELECT"), false);

使用 false 参数,您允许 RFT 在所有页面元素中搜索,而不仅仅是在您之前记录的元素中搜索。

如果页面只有一个Html.SELECT,可以直接使用SelectGuiSubitemTestObject类型的方法select(String value)。否则,首先您必须循环遍历之前找到的对象并搜索包含您想要 select 的文本的对象。然后,您的代码将变为:

public static void clickDropdown(String name) {
   // Prepare finding properties
   Property[] props = new Property[2];
   props[0] = new Property(".class", "Html.SELECT");
   props[1] = new Property(".text", new RegularExpression(".*" + name + ".*", false));
   // Find al select items inside the current page
   TestObject slcs = find(atDescendant(props), false);
   // Interact with the element
   if (slcs.length > 0)
      ((SelectGuiSubitemTestObject) slcs[0]).select(name);
}

在这种情况下你不能直接在find方法中使用.text,因为select的.text 属性的值等于到其所有值的串联。所以,你必须使用 RegularExpression.

警告:当且仅当您正在搜索的对象在搜索操作时已完全加载到页面中时,find 方法才有效。

使用动态查找 技术可能比使用 RFT 直接记录的元素慢。不幸的是,如果您的 UI 具有动态元素的 ID,这是与它们交互的唯一方式。

this blog 中给出了一些提高动态查找方法性能的提示。

1) Object Selection : Here you need to find the right set of objects to search on. Let's call the selected objects as landmarks, which is what we use when we have to move from one place to another in real world.

2) Search Type: Second important decision to make is how do you want to search on the selected object.

3) Property selection : We have found the object on which we want to make a search, we have also figured out the scope of search within the object children hierarchy, now is the time to decide what parameters we like to pass to our search type.

4) Memory cleanup : Last but equally important thing to remember while using objects returned by find is to free the objects as soon as the work is done or whenever you feel that the object might have changed in the AUT as part of some intermediate transaction.

我正在开发一个基于 RFT 的小型框架,让您无需任何录制操作即可编写脚本。如果您有兴趣,请告诉我。

希望这对您有所帮助:)