WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with MSIE
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Working with Multiple Tabs in Internet Explorer

 Keywords: Tab Tabs MSIE IE Internet Explorer Multiple  

Question:

Is there a way where I can open sites in multiple tabs, and working on it one by one by scraping data to those sites.

Basically I am trying to navigate multiple url parameters(via CSV) but one siteload takes long so I need to open multiple tabs to save time while waiting each page to load successfully. And I need to have an ID for each tab so I can go back and navigate each of them.

It's like retrieving/manipulating each IE document for each of the tab with sites opened.

Answer:

There doesn't seem to be a direct way to reference indivial tabs in IE via COM. However one trick is the use the windows shell to rename the various IE tab s then reference the document object based on the revised tab title.

For multi-tabs, your script will require some constants:

navOpenInNewWindow=1
navNoHistory=2
navNoReadFromCache=4
navNoWriteToCache=8
navAllowAutosearch=16
navBrowserBar=32
navHyperlink=64
navEnforceRestricted=128
navNewWindowsManaged=256
navUntrustedForDownload=512
navTrustedForActiveX=1024
navOpenInNewTab=2048
navOpenInBackgroundTab=4096
navKeepWordWheelText=8192
navVirtualTab=16384
navBlockRedirectsXDomain=32768
You start IE in the usual way:
oIE = CreateObject("InternetExplorer.Application")
oIE.visible = 1
For this example, assume we want to open 3 tabs and later change the reference to the 2nd tab. Let's declare a constant and place the urls into a list:
numURL=3
urls=http://forum.winbatch.com|http://techsupt.winbatch.com|http://www.winbatch.com

So, with our object created, a simple loop will load the urls into tabs:
For i=1 To numURL
   cURL=ItemExtract(i,urls,"|")
   If i==1
      oIE.Navigate(::url=cURL,Flags=navNoReadFromCache)
   Else
      oIE.Navigate2(::url=cURL,Flags=navOpenInNewTab)
   Endif
   Display(10,"Loading...",cURL) 
Next
The thing to notice is that each tab's title does not equate to the url. This is where the suggestion comes in for keeping track. Having previously set a constant for the number of tabs, you can simply rename each tab TAB+tabnumber. In order to do this the shell object comes in handy, and how about a little udf renameTabs():
#DefineSubRoutine renameTabs()
oShell = CreateObject("Shell.Application")
nTab=1
ForEach obj In oShell.Windows
   If StrIndexNC(obj.fullname, "iexplore.exe", 1, @FWDSCAN) 
      cTab="TAB":nTab
      nTab=nTab+1
      obj.Document.Body.Document.Title=cTab
   Endif
Next
oShell=0
Return(1)
#EndSubRoutine
This assumes the tabs will equal numURL but there is no reason at this stage they shouldn't. And now the display is changed:

This makes it easier to reference the url based on it's tab 'order' [for lack of a better concept]. To illustrate how the concept can work, let's re-navigate the second tab to Google with

cURL="www.google.com"
setTab(2,cURL)
and another simple udf using the shell:
#DefineSubRoutine setTab(nTab,cURL)
t1="TAB":nTab
oShell = CreateObject("Shell.Application")
ForEach obj In oShell.Windows
   If StrIndexNC(obj.fullname, "iexplore.exe", 1, @FWDSCAN) 
      If obj.Document.title == t1
         obj.Navigate2(cURL)    ;use Navigate2 to change the url in the exisiting tab
         Display(10,"re-navigating %t1% to ",cURL)
       Endif
   Endif
Next
oShell=0
Return(1)
#EndSubRoutine
You could set oIE=obj to carry out further functionality with a specific tab.
Article ID:   W18135
Filename:   Working with Multiple Tabs in Internet Explorer.txt
File Created: 2013:06:19:13:49:10
Last Updated: 2013:06:19:13:49:10