rgratis
12 years agoFrequent Contributor
How to match a Page object to its BrowserWindow
What methods have people come up with to match a Page object to its BrowserWindow? Both items are at the same level, as children of the Browser object. A quick idea I had was checking for the "Focused" BrowserWindow, which I assume would contain my active page, but I'm wondering if I have missed a simpler or more robust method.
- I contacted support as I was curious if they had a solution. This is their reply:
----------------------------
[JScript]
function getBrowserWindowByPage(page)
{
if (page != null && aqString.Compare(page.ObjectType,"Page",false) == 0)
{
var title = page.contentDocument.title;
var wnd = page.Parent.FindChild("WndCaption", title + "*");
if (wnd.Exists)
return wnd;
}
return null;
}
function main()
{
var browserWindowFF = getBrowserWindowByPage(Sys.Browser("firefox").Page("http://smartbear.com/"));
var browserWindowChrome = getBrowserWindowByPage(Sys.Browser("chrome").Page("http://smartbear.com/"));
var browserWindowIE = getBrowserWindowByPage(Sys.Browser("iexplore").Page("http://smartbear.com/"));
}
The getBrowserWindowByPage function works across all browsers. I've tested it with the Firefox v.24, Chrome v.30, and IE v.10 browsers.
----------------------------
The key must be "page.contentDocument.title" which must always match up to "WndCaption" on the browser window objects. Hopefully that is it!
I've still asked them to add it as a build-in feature.