Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript / selenium: get the window from the document object

I am writing user extensions to selenium. I have the document object. How can I get the window object of the window that contains my document?

PageBot.prototype.locateElementByMyLocator= function(text, inDocument) {
     // I want the window here
}
like image 817
flybywire Avatar asked Feb 28 '23 17:02

flybywire


2 Answers

In IE it's document.parentWindow; in Mozilla it's document.defaultView.

Thus you could do something like

function getDocWindow(doc) {
  return doc.parentWindow || doc.defaultView;
}
like image 113
Pointy Avatar answered Mar 06 '23 07:03

Pointy


If you are writing your own extension you can get a window object in Selenium by going

Selenium.prototype.doExtensionStuff(){
   var doc = this.browserbot.getUserWindow().document; //This returns the document that Selenium is using

}

This is seen as a better way of doing and will work on any browser since Selenium is taking care of the different browser nastiness

like image 31
AutomatedTester Avatar answered Mar 06 '23 06:03

AutomatedTester