ObjChildItem.Click() not working properly in a loop

可紊 提交于 2020-05-16 22:01:43

问题


I am using UFT One to test a Salesforce Contacts table with two rows that have clickable links, "Jim Bean" and "Marsha Smith". (see attached image). I want to loop through the rows and click on the links and have "ValidateContactProperties" Action get called for each Contact Details page that comes up.

The following code works but ObjChildItem.Click() gets executed only the first time. Only Jim Bean's contact profile page is displayed, not Marsha Smith's.

For i = 2 to rowCount

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

       ObjChildItem.Click()

       RunAction "ValidateContactProperties", oneIteration

Next

I can see ObjChildItem has Marsh Smith's URL and info but the page is still displaying Jim Bean's Contact Details page after ObjChildItem.Click() is executed for Marsha Smith.

How can we get Marsh Smith's Contact Details page to come after Jim Bean's?

****** 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

回答1:


****** 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




回答2:


The problem you're facing is probably that the Click causes the browser to change the HTML DOM thus invalidating the objects in the Obj array. To understand why this happens please read this blog post.

In order to solve the issue you have to move the code that initializes Obj into the loop so there are valid objects for each loop iteration.



来源:https://stackoverflow.com/questions/61368570/objchilditem-click-not-working-properly-in-a-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!