Latest IE version browser handling through QTP - Printable Version +- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums) +-- Forum: General (https://www.learnqtp.com/forums/Forum-General) +--- Forum: Suggestions and Feedback (https://www.learnqtp.com/forums/Forum-Suggestions-and-Feedback) +--- Thread: Latest IE version browser handling through QTP (/Thread-Latest-IE-version-browser-handling-through-QTP) |
Latest IE version browser handling through QTP - satya_251 - 11-08-2011 Hi there are two function which were provided below to handle latest IE browser which may help any one in geeting problems sue to the same Function1 Public Function openBrowser(URL) Collecting current version of IE for future reference Set FSO = CreateObject("Scripting.FileSystemObject") IEVersion = FSO.GetFileVersion("C:\Program Files\Internet Explorer\iexplore.exe") Environment("IEVersion")=IEVersion Creating a Dictionary object for storing all the open browser at this point of time Set wndHndlr = CreateObject("Scripting.Dictionary") ' Browser & Page objects Set oBrowser = Description.Create oBrowser("micclass").Value = "Browser" Set oPage = Description.Create oPage("micclass").Value = "Page" 'Get all browsers open on desktop Set allBrowser = Desktop.ChildObjects(oBrowser) iCount = allBrowser.Count Storing hwnd of all browsers in a dictionary object For i = 0 To iCount-1 wndHndlr.Add allBrowser(i).GetROProperty("hwnd"), allBrowser(i).GetROProperty("title") Next ' Creating IE object and Navigating to URL Set oIE = CreateObject("InternetExplorer.Application") oIE.visible = 1 oIE.Navigate2 URL WaitCount = 0 'Checking if IE is in ready state Do While oIE.ReadyState <> 4 And WaitCount < 50 Wait(2) WaitCount=WaitCount+1 Loop ' Checking current version of IE for handling IE7 differently If cINt(left(IEVersion,1))<= cInt(6) Then 'Do Nothing Else wndHndlr.Add oIE.hwnd,oIE.hwnd End If 'Get all browsers open on desktop, including recently opened browsers Set allBrowser = Desktop.ChildObjects(oBrowser) iCount = allBrowser.Count For i=0 to iCount-1 'Get the active Browser object Set oBrowserObject = allBrowser(i) 'Get the URL of the ' Checking if browser existed before if no assign environment variables If wndHndlr.Exists(oBrowserObject.GetROProperty("hwnd")) Then 'Do nothing Else oBrowser("hwnd").Value = oBrowserObject.GetROProperty("hwnd") oPage("hwnd").Value = Browser(oBrowser).Page("micclass:=Page","title:=.*").GetROProperty("hwnd")' Environment("Browser_hwnd") = oBrowser("hwnd").Value Environment("Page_hwnd") = oPage("hwnd").Value Exit For End If Next ' Returning Page object Set openBrowser = Browser(oBrowser).Page(oPage) End Function Function2 Public Function getHwnd(strBrowserTitle) Set oBrowser = Description.Create oBrowser("micclass").Value = "Browser" Set oPage = Description.Create oPage("micclass").Value = "Page" 'Get all browsers Set allBrowser = Desktop.ChildObjects(oBrowser) Dim i, iCount iCount = allBrowser.Count - 1 For i = 0 To iCount 'Get the active Browser object Set oBrowserObject = allBrowser(i) 'Get the URL of the If InStr(oBrowserObject.GetROProperty("title"), strBrowserTitle) => 0 Then If oBrowserObject.GetROProperty("hwnd") <> Environment("Browser_hwnd") Then oBrowser("hwnd").Value = oBrowserObject.GetROProperty("hwnd") oPage("hwnd").Value = Browser(oBrowser).Page("micclass:=Page","title:=.*").GetROProperty("hwnd")' 'allBrowser(i).ChildObjects(oPage)(0).GetROProperty("hwnd") Environment("PBrowser_hwnd") = oBrowser("hwnd").Value Exit For End If End If Next Set getHwnd = Browser(oBrowser).Page(oPage) End Function |