最好的辦法是獲取元素類和使用索引看看元素的索引有多長,以及如何使用高亮方法標識元素。獲取索引計數,編寫邏輯在數據表中捕獲它們,一旦索引達到最高(您可以知道前一個索引是否工作,但下一個索引拋出錯誤,最後一個索引是元素的最大索引。必須強調你找到的最後一個元素,它將加載複製一些舊網格的新網格,因爲你將通過給出索引0或某物而得到一些舊網格。現在,你必須通過使用高亮來確定哪個索引將給你下一個網格並獲取索引以捕獲下一次加載的數據,再次突出顯示最後一個要重新加載的網格,並使用您找到的索引作爲新記錄捕獲,並通過for循環再次重複它們。就像之前發現的網格一樣,因爲它們可能包含全集或更少,這裏代碼可能會使用先前的邏輯記錄一些重複內容 否w您需要使用一些代碼刪除重複的記錄。
由於所有列和行具有相同的屬性但索引不同,因此執行以下操作。頁面加載的記錄第一次是69,但是第二次加載89有25個重複記錄。這可能與您的網頁有所不同。我的頁面包含5列。
Dim HighlitedElement, PreviousHighlitedElement, StartingElement, EndingElement
Set cpLookup= browser("name:=Legal Entity Search - QA1").page("title:=Legal Entity Search - QA1")
PreviousHighlitedElement=""
datatable.AddSheet ("CounterParty_Lookup").AddParameter "Name",""
datatable.AddSheet ("CounterParty_Lookup").AddParameter "LE_Number",""
datatable.GetSheet("CounterParty_Lookup").AddParameter "Oracle_Number",""
datatable.GetSheet("CounterParty_Lookup").AddParameter "Effective_Date",""
datatable.GetSheet("CounterParty_Lookup").AddParameter "Termination_Date",""
CurrentColumn=1
CurrentRow=1
StartingElement=0
EndingElement=69
For j = 0 To 100 Step 1
If not j = 0 and DuplicateRecord=false Then
StartingElement=0+25
EndingElement=44+20+25
End If
arrayElement=0
For i = StartingElement To EndingElement Step 1
datatable.GetSheet("CounterParty_Lookup").SetCurrentRow(CurrentRow)
Select Case CurrentColumn
Case 1
If cpLookup.webelement("html id:=","html tag:=DIV", "index:="&i,"class:=ui-grid-cell-contents ng-binding ng-scope").exist(2) Then
datatable.Value ("Name", "CounterParty_Lookup")=cpLookup.webelement("html id:=","html tag:=DIV", "index:="&i,"class:=ui-grid-cell-contents ng-binding ng-scope").getroproperty("outertext")
CurrentColumn=CurrentColumn+1
Else
notfound = true
Exit for
End If
Case 2
datatable.Value ("LE_Number", "CounterParty_Lookup")=cpLookup.webelement("html id:=","html tag:=DIV", "index:="&i,"class:=ui-grid-cell-contents ng-binding ng-scope").getroproperty("outertext")
CurrentColumn=CurrentColumn+1
Case 3
datatable.Value ("Oracle_Number", "CounterParty_Lookup")=cpLookup.webelement("html id:=","html tag:=DIV", "index:="&i,"class:=ui-grid-cell-contents ng-binding ng-scope").getroproperty("outertext")
CurrentColumn=CurrentColumn+1
Case 4
datatable.Value ("Effective_Date", "CounterParty_Lookup")=cpLookup.webelement("html id:=","html tag:=DIV", "index:="&i,"class:=ui-grid-cell-contents ng-binding ng-scope").getroproperty("outertext")
CurrentColumn=CurrentColumn+1
Case 5
datatable.Value ("Termination_Date", "CounterParty_Lookup")=cpLookup.webelement("html id:=","html tag:=DIV", "index:="&i,"class:=ui-grid-cell-contents ng-binding ng-scope").getroproperty("outertext")
CurrentColumn=1
CurrentRow=CurrentRow+1
End Select
Next
HighlitedElement=cpLookup.webelement("html id:=","html tag:=DIV", "index:="&i-5,"class:=ui-grid-cell-contents ng-binding ng-scope").getroproperty("outertext")
cpLookup.webelement("html id:=","html tag:=DIV", "index:="&i-5,"class:=ui-grid-cell-contents ng-binding ng-scope").highlight
If HighlitedElement=PreviousHighlitedElement or notfound Then
Exit for
else
PreviousHighlitedElement= HighlitedElement
End If
Next
' (to indicate as duplicated record and get the exect count of the rows)
TotalInitialRows=datatable.GetSheet("CounterParty_Lookup").GetCurrentRow-1
CurrentRow=CurrentRow-20
DuplicatedRecord=0
'Msgbox TotalInitialRows
If TotalInitialRows > 20 Then
For eachrow= CurrentRow To TotalInitialRows Step 1
datatable.GetSheet("CounterParty_Lookup").SetCurrentRow(eachrow)
currentValue=datatable.Value ("Name", "CounterParty_Lookup")
For totalRow = eachrow To TotalInitialRows Step 1
newrow=totalRow+1
datatable.GetSheet("CounterParty_Lookup").SetCurrentRow(newrow)
ncurrentValue=datatable.Value ("Name", "CounterParty_Lookup")
If ncurrentValue=currentValue and currentValue <> "DuplicatedRecord" Then
DuplicatedRecord=1+DuplicatedRecord
datatable.Value ("Name", "CounterParty_Lookup")="DuplicatedRecord"
Exit for
End If
Next
Next
End If
TotalRows=TotalInitialRows-DuplicatedRecord
Msgbox TotalRows