ObjChildItem.Click()在循环中无法正常工作 [英] ObjChildItem.Click() not working properly in a loop

查看:85
本文介绍了ObjChildItem.Click()在循环中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UFT One来测试Salesforce Contacts表,该表具有两行具有可单击链接的"Jim Bean"和"Marsha Smith". (请参见附件图片). 我想遍历行并单击链接,并为出现的每个联系详细信息"页面调用"ValidateContactProperties"操作.

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.

以下代码有效,但是ObjChildItem.Click()仅在第一次执行.仅显示Jim Bean的联系人个人资料页面,而不显示Marsha Smith的联系人个人资料页面.

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

我可以看到ObjChildItem具有Marsh Smith的URL和信息,但是在为Marsha Smith执行ObjChildItem.Click()之后,该页面仍显示Jim Bean的Contact Details页面.

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.

我们如何才能在Jim Bean之后获得Marsh 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

推荐答案

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

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

我找到了一个解决方案,虽然不优雅,但可以使用.

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

----------------- ----循环联系人操作-------------------

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

设置oDesc = Description.Create oDesc("micclass").value ="WebTable"

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

设置obj =浏览器("Contacts | Salesforce").Page("Contacts | Salesforce").ChildObjects(oDesc)

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

如果obj什么都不是,则 打印"obj不存在" 其他

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")

'全局变量最初设置为2
对于i = gloVarIteration到rowCount

' 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      

如果结束

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

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

如果gloVarIteration> 2然后 '如果我们不在循环的第一个迭代中,请刷新页面,否则DOM将会混乱并且UFT将无法识别任何对象. Browser("James Bean | Salesforce").Refresh() 如果结束

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

如果Browser("James Bean | Salesforce").Page("James Bean | Salesforce").WebTabStrip("RelatedDetailsNewsMore").Exist(15)然后

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()

如果结束

这篇关于ObjChildItem.Click()在循环中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆