The application I'm testing has a particular feature which I'm having some trouble automating. We click a View button, and it immediately opens up 'x' amount of tabs which are all reports generated. We want to open each tab, and then close it out. The problem (I think) is we're using the CreationTime to get each tab as we thought that it'd go sequentially. We've later figured out that the CreationTime of the tabs, when the application opens up 4 new tabs, is:
0 (original application)
2 (first tab)
1 (second tab)
3 (third tab)
4 (fourth tab)
Here's what the code looks like.
What's happening is UFT is giving an error saying 'Object not visible'. So I believe it's either related to the .highlight not correctly bringing into focus the tab, or the order in which the tab's are created is causing issue. The strange part is, sometimes it works flawlessly.
Dim index, array_of_handles()
tabcount = Browser("CreationTime:=0").GetROProperty("number of tabs") 'get the number of tabs open
index = CInt(tabcount-1) 'subtract 1 from the tab count to remove the tab we want to leave open (the application)
ReDim array_of_handles(index) 'ReDim our array to the correct size of the number of tabs we have
'Loop to get each tab's handle starting from the last tab open
For i = index to 1 Step -1
array_of_handles(i) = Browser("CreationTime:=" & i).GetROProperty("hwnd")
'Loop through each handle, screenshot, close tab, note we never populate the 0 index so it's always empty
For i = 1 To index Step 1
Set tab_object = Browser("hwnd:=" & array_of_handles(i))
tab_object.highlight 'try to highlight to bring the tab into focus
wait 5 'wait 5 seconds for assurance
Can anyone recommend a better (more reliable) way to accomplish this?