Automated tests ObjChildItem.Click()在循环中工作不正常

Automated tests ObjChildItem.Click()在循环中工作不正常,automated-tests,salesforce,qtp,hp-uft,Automated Tests,Salesforce,Qtp,Hp Uft,我正在使用UFT One测试Salesforce Contacts表,该表有两行可点击的链接,“Jim Bean”和“Marsha Smith”。(见附图)。 我想在各行中循环并单击链接,并为出现的每个联系人详细信息页面调用“ValidateContactProperties”操作 下面的代码可以工作,但ObjChildItem.Click()只在第一次执行。只显示Jim Bean的联系人档案页面,而不显示Marsha Smith的 For i = 2 to rowCount S

我正在使用UFT One测试Salesforce Contacts表,该表有两行可点击的链接,“Jim Bean”和“Marsha Smith”。(见附图)。 我想在各行中循环并单击链接,并为出现的每个联系人详细信息页面调用“ValidateContactProperties”操作

下面的代码可以工作,但ObjChildItem.Click()只在第一次执行。只显示Jim Bean的联系人档案页面,而不显示Marsha Smith的

For i = 2 to rowCount

       Set ObjChildItem = obj(0).ChildItem(i,3,"Link", 0)

       ObjChildItem.Click()

       RunAction "ValidateContactProperties", oneIteration

Next
我可以看到ObjChildItem包含Marsh Smith的URL和信息,但在为Marsha Smith执行ObjChildItem.Click()后,页面仍显示Jim Bean的联系人详细信息页面。

我们怎样才能让Marsh Smith的联系方式页面位于Jim Bean之后

****** WORKING CODE  *********

I found a solution, it is not elegant but it works.

----------------- ----   Loop Through Contacts action  -------------------

Set oDesc = Description.Create
oDesc("micclass").value = "WebTable"

Set obj = Browser("Contacts | Salesforce").Page("Contacts | Salesforce").ChildObjects(oDesc)

If obj is Nothing  Then
    Print "obj does not exist"
Else
        
    ' get the number of rows in the contacts table
    rowCount = obj(0).GetROProperty("rows")
      
 ' global variable is initially set to 2  
    For i = gloVarIteration to rowCount
           
         If  gloVarIteration > 3 Then
            ' refresh the page if we are not in the first ieration of the loop, otherwise the DOM will gte messed up and UFT won't be able to recognize any objects.
            Browser("Contacts | Salesforce").Refresh()
            wait(5)
            Set obj = Browser("Contacts | Salesforce").Page("Contacts | Salesforce").ChildObjects(oDesc)
        End If
       
        Set ObjChildItem = obj(0).ChildItem(i,3,"Link", 0)
        If ObjChildItem is Nothing  Then
            Print "ObjChildItem does not exist"
        Else      
               
        ' bring up the Contact profile
        ObjChildItem.Click()
        
        ' call the action to validate Contact profile data values            
        RunAction "ValidateContactProperties", oneIteration
                           
        End  If
    Next      
End  If



---------------  ValidateContactProperties   action --------------------

If  gloVarIteration > 2 Then
    ' refresh the page if we are not in the first ieration of the loop, otherwise the DOM will gte messed up and UFT won't be able to recognize any objects.
    Browser("James Bean | Salesforce").Refresh()
End If

If Browser("James Bean | Salesforce").Page("James Bean | Salesforce").WebTabStrip("RelatedDetailsNewsMore").Exist(15) Then

.......  do stuff

        'increment global variable
        gloVarIteration = gloVarIteration + 1

        ' go back to Contacts page
         Browser("James Bean | Salesforce").Back()

End If

您面临的问题可能是,
单击
会导致浏览器更改HTML DOM,从而使
Obj
数组中的对象无效。要理解为什么会发生这种情况,请阅读本文


为了解决这个问题,您必须将初始化
Obj
的代码移动到循环中,以便每个循环迭代都有有效的对象。

*******工作代码*********

我找到了一个解决方案,它不是优雅的,但它是有效的

---------------------通过触点动作循环-------------------

Set oDesc=Description.Create ODEC(“micclass”).value=“WebTable”

设置obj=浏览器(“联系人| Salesforce”).页面(“联系人| Salesforce”).子对象(ODEC)

如果obj不算什么,那么 打印“obj不存在” 否则

'全局变量最初设置为2
对于i=行计数的glovaritation

     If  gloVarIteration > 3 Then
        ' refresh the page if we are not in the first ieration of the loop, otherwise the DOM will gte messed up and UFT won't be able to recognize any objects.
        Browser("Contacts | Salesforce").Refresh()
        wait(5)
        Set obj = Browser("Contacts | Salesforce").Page("Contacts | Salesforce").ChildObjects(oDesc)
    End If

    Set ObjChildItem = obj(0).ChildItem(i,3,"Link", 0)
    If ObjChildItem is Nothing  Then
        Print "ObjChildItem does not exist"
    Else      

    ' bring up the Contact profile
    ObjChildItem.Click()

    ' call the action to validate Contact profile data values            
    RunAction "ValidateContactProperties", oneIteration

    End  If
Next      
如果结束

---------------ValidateContactProperties操作--------------------

如果舌音变异>2,则 '如果我们不在循环的第一个分区中,请刷新页面,否则DOM将出错,UFT将无法识别任何对象。 浏览器(“James Bean | Salesforce”).Refresh() 如果结束

如果浏览器(“James Bean | Salesforce”).Page(“James Bean | Salesforce”).WebTabStrip(“RelatedDetails Newmore”)

。。。。。。。做事

    'increment global variable
    gloVarIteration = gloVarIteration + 1

    ' go back to Contacts page
     Browser("James Bean | Salesforce").Back()

如果我想出来了,就结束吧。您必须添加浏览器(“名称”)。返回到从循环调用的操作中。@Burak,如果您添加了
Browser.Back
,则需要重新调用
ChildObjects
。这并没有解决我的问题。这是我的For循环ObjChildItem.Click()运行操作“ValidateContactProperties”,oneIteration Set obj=Browser(“Contacts | Salesforce”).Page(“Contacts | Salesforce”).ChildObjects(ODEC)这不是一个完整的循环,你能把代码放在问题中吗?对不起,我看不出问题所在。祝你好运:)
    'increment global variable
    gloVarIteration = gloVarIteration + 1

    ' go back to Contacts page
     Browser("James Bean | Salesforce").Back()