最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

firefox - javascriptselenium: get the window from the document object - Stack Overflow

programmeradmin1浏览0评论

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
}

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
}
Share Improve this question asked Jan 25, 2010 at 16:16 flybywireflybywire 274k201 gold badges405 silver badges509 bronze badges 1
  • 1 How did you get the document object in the first place? I seem unable to fetch it during the test run... – Marco Faustinelli Commented Sep 17, 2014 at 15:14
Add a ment  | 

2 Answers 2

Reset to default 4

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;
}

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

发布评论

评论列表(0)

  1. 暂无评论