3

我用 html 创建了一个简单的表单,它有两个对象(编辑框 - 名字),具有相同的属性(如名称、输入和其他),一个在另一个之下。我在其中一个编辑框中记录了一个动作,并将对象添加到本地对象存储库中,索引为“0”(因为它在源代码中的顺序)。

然后我将 Index 的值修改为“1”,这样同一个对象将引用具有相同属性的第二个编辑框,但它不会在 QTP 中发生。

添加序号标识符后,尽管我们在对象存储库中对其进行了修改,但它确实在存储库中得到了更新,我们可以查看相同的内容。但是在修改时它的行为并不像它那样,即在这种情况下,当我们运行脚本时,它应该引用第二个“名字编辑框”,但它并没有发生,为什么?

简要介绍一下我的问题,在对象存储库中修改后的序号标识符并没有真正更新,即使它显示为已更新,为什么?

4

1 回答 1

2

There is a web specific optimization in QTP which you seem to have run into. In addition to the regular description QTP stores the sourceIndex as a hidden property. Then when trying to identify the object it will first check if the HTML object with the stored sourceIndex matches the description, if it does it assumes that it's the correct object and doesn't search the whole DOM.

Since the ordinal (index in this case) is a special property that is used for identification only if multiple objects match, the sourceIndex optimization circumvents usage of the index.

In later versions of QTP (from 11 I think) QTP also stores a generated XPath to the object which has similar functionality. You can disable these optimizations in Tools → Options → Web → Advanced

screen shot of options

于 2013-04-14T07:27:37.837 回答