gpt4 book ai didi

automated-tests - ObjChildItem.Click() 在循环中不能正常工作

转载 作者:行者123 更新时间:2023-12-04 10:10:10 24 4
gpt4 key购买 nike

我正在使用 UFT One 来测试 Salesforce 联系人表,其中两行具有可点击的链接“Jim Bean”和“Marsha Smith”。 (见附图)。
enter image description here
我想遍历行并单击链接,并为出现的每个联系人详细信息页面调用“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 的联系方式页面。
enter image description here

我们怎样才能让 Marsh Smith 的 Contact Details 页面出现在 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

最佳答案

您面临的问题可能是 Click导致浏览器更改 HTML DOM 从而使 Obj 中的对象无效大批。要了解为什么会发生这种情况,请阅读此 blog post .

为了解决这个问题,你必须移动初始化 Obj 的代码。进入循环,因此每次循环迭代都有有效的对象。

关于automated-tests - ObjChildItem.Click() 在循环中不能正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61368570/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com