Javascript / selenium: get window from document object

I am writing custom extensions for selenium. I have a document object. How can I get the window object of the window containing my document?

 PageBot.prototype.locateElementByMyLocator= function(text, inDocument) { // I want the window here } 
+4
source share
2 answers

In IE, this is document.parentWindow; in Mozilla, this is document.defaultView.

So you can do something like

 function getDocWindow(doc) { return doc.parentWindow || doc.defaultView; } 
+4
source

If you write your own extension, you can get the window object in Selenium by going to

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

This is considered the best way to do it and will work in any browser, since Selenium takes care of different mucks of the browser

+4
source

Source: https://habr.com/ru/post/1299335/


All Articles