JavaScript / Selenium:从文档对象获取窗口

4

我正在编写selenium的用户扩展。我有document对象。如何获取包含我的文档的窗口的window对象?

PageBot.prototype.locateElementByMyLocator= function(text, inDocument) {
     // I want the window here
}

1
你是如何首先获取文档对象的?在测试运行期间,我似乎无法获取它... - Marco Faustinelli
2个回答

4
在IE中,它是document.parentWindow;在Mozilla中,它是document.defaultView。
因此,您可以像这样做:
function getDocWindow(doc) {
  return doc.parentWindow || doc.defaultView;
}

4
如果您正在编写自己的扩展程序,您可以通过以下方式在Selenium中获取窗口对象:

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

}

这被视为更好的方法,因为Selenium会处理不同浏览器的难搞问题,任何浏览器都可以使用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接