javascript / selenium:从文档对象中获取窗口

时间:2010-01-25 16:16:15

标签: javascript firefox dom selenium document

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

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

2 个答案:

答案 0 :(得分:4)

在IE中它是document.parentWindow;在Mozilla中,它是document.defaultView。

因此你可以做类似

的事情
function getDocWindow(doc) {
  return doc.parentWindow || doc.defaultView;
}

答案 1 :(得分:4)

如果你正在编写自己的扩展,你可以通过

在Selenium中获得一个窗口对象
Selenium.prototype.doExtensionStuff(){
   var doc = this.browserbot.getUserWindow().document; //This returns the document that Selenium is using

}

这被视为一种更好的做法,并且可以在任何浏览器上运行,因为Selenium正在处理不同的浏览器肮脏

相关问题