How to get browser instance count and tab count
- 9 years ago
This is how I would get the Browser instant count and count of tabs for individual browsers.
Sub Test2 Dim browser, brwsrs, brwsr, pagecount brwsrs = Sys.FindAll("ObjectType","Browser") Log.Message("BrowserCount: " & UBound(brwsrs)+ 1) FOR EACH brwsr IN brwsrs pagecount = 0 pagecount = brwsr.FindAll("ObjectType","Page") Log.Message(brwsr.ObjectIdentifier & " Pages:" & UBound(pagecount) + 1) NEXT END SUB
This gives the output:
BrowserCount: 2
chrome Pages:1
firefox Pages:3All counts are correct according to what browsers and tabs I had open on the system.
NOTE: Firefox has an additional count of 1 (I had 2 tabs open), because it has an additonal page object in the object browser. You can read about it here : UIPage object in Firefox
For keeping track of tabs and refering to particular ones, this is what I do:
SUB Test3 Call Browsers.Item("firefox").Navigate("about:blank") Set browser = Aliases.browser Call browser.ToUrl("http://firefox.tab02/") Browser.Page("http://firefox.tab02/").Close End Sub
When I open a new tab I give it a URL like this : "http://firefox.tab1"
I will open the next tab, I'll give it a URL "http://firefox.tab2"
Obviously no page like that exists, but I can refer to the tabs I want by addressing the using the URL (Last line of code in above sub).
Hope these help.
- 9 years ago
Thanks DJadhav. :)
A small problem here, If same browser instance open multiple time then it will given wrong count (tab count)
like - Browser count : 2
iexplorer pages : 4
iexplorer pages : 4