Need UFT to close duplicate tabs in Chrome
Category:
Question ID: 109898
1
0

I have Chrome set to restore specific tabs so on startup it loads the previous URLs that were open in the browser.

I use SystemUtil.Run to launch Chrome, and when I do, I now have duplicate tabs on the browser, which confuses UFT and it won’t interact with the correct objects.

Is there a way to close all duplicate restored tabs with the same title and URL but keep only one open? I want to keep the tab restore setting so that other sites will restore.

Marked as spam
Posted by (Questions: 386, Answers: 64)
Asked on October 28, 2020 3:19 pm
574 views
Answers (1)
1
Private answer

Below is some example code that will close tabs based on when they were created. You could modify the code to close the tabs that launch with Chrome, or even add some code to read the tab titles and URL and use logic to decide which to leave open and which to close. Keep in mind that browser tabs index begin with 0. I hope this helps.

SystemUtil.Run "C:Program Files (x86)GoogleChromeApplicationchrome.exe"
wait(1)

iTabs = Browser("CreationTime:=0").GetROProperty("number of tabs")

'msgbox iTabs

Browser("CreationTime:=0").OpenNewTab
Browser("CreationTime:=" & iTabs).Navigate "https://smile.amazon.com/"

Browser("CreationTime:=0").OpenNewTab
Browser("CreationTime:=" & iTabs+1).Navigate "https://www.eyeontesting.com/"

Browser("CreationTime:=0").OpenNewTab
Browser("CreationTime:=" & iTabs+2).Navigate "https://www.google.com/"

iNewTabs = Browser("CreationTime:=0").GetROProperty("number of tabs")
'msgbox iNewTabs

For iCloseTabs = iNewTabs-1 to iTabs step -1
print "iCloseTabs = " & iCloseTabs
Browser("CreationTime:=" & iCloseTabs).Close
Next

Browser("Google").CloseAllTabs

Marked as spam
Posted by (Questions: 16, Answers: 807)
Answered on October 28, 2020 3:23 pm
0
I was able to modify your code to suit my needs. Thanks for the example!
( at October 28, 2020 3:25 pm)
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top