ObjChildItem.Click () не работает должным образом в цикле - PullRequest
1 голос
/ 22 апреля 2020

Я использую UFT One, чтобы протестировать таблицу контактов Salesforce с двумя строками, которые имеют интерактивные ссылки: «Джим Бин» и «Марша Смит». (см. прикрепленное изображение). enter image description here Я хочу провести l oop по строкам, щелкнуть ссылки и вызвать действие «ValidateContactProperties» для каждой появившейся страницы сведений о контакте.

Следующий код работает, но ObjChildItem.Click () выполняется только в первый раз. Отображается только страница профиля контакта Джима Бина, а не Марша Смит.

For i = 2 to rowCount

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

       ObjChildItem.Click()

       RunAction "ValidateContactProperties", oneIteration

Next

Я вижу, что у ObjChildItem есть Мар sh URL-адрес Смита и информация, но страница все еще отображает страницу с контактной информацией Джима Бина после ObjChildItem.Click () выполнен для Марши Смит. enter image description here

Как мы можем получить на март sh страницу с контактными данными Смита, которая появится после Джима Бина?

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

1 голос
/ 28 апреля 2020

****** КОД РАБОТЫ *********

Я нашел решение, оно не элегантно, но работает.

----- ------------ ---- L oop Действие «Через контакты» -------------------

Установить oDes c = Описание. Создание oDes c ("micclass"). Value = "WebTable"

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

Если obj равен Nothing, тогда вывести «obj не существует». Иначе

' get the number of rows in the contacts table
rowCount = obj(0).GetROProperty("rows")

'Глобальная переменная изначально установлена ​​в 2
Для 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 --------------- -----

Если gloVarItered> 2, то 'refre sh обновить страницу, если мы не на первой итерации l oop, иначе DOM будет испорчен, а UFT - нет уметь распознавать любые объекты. Браузер («James Bean | Salesforce»). Refre sh () End If

If Browser («James Bean | Salesforce»). Страница («James Bean | Salesforce»). WebTabStrip («RelatedDetailsNewsMore» ) .Exist (15) Тогда

....... делать вещи

    'increment global variable
    gloVarIteration = gloVarIteration + 1

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

End If

0 голосов
/ 22 апреля 2020

Проблема, с которой вы сталкиваетесь, вероятно, заключается в том, что Click заставляет браузер изменить HTML DOM, тем самым лишая законной силы объекты в массиве Obj. Чтобы понять, почему это происходит, прочитайте это сообщение в блоге .

. Чтобы решить эту проблему, необходимо переместить код, инициализирующий Obj, в l oop, чтобы действительные объекты для каждой итерации l oop.

...