对象不支持属性或方法" attachevent"

时间:2016-05-03 12:53:22

标签: javascript java selenium

我在selenium.jar中启动IE 11时遇到了问题。

我用Google搜索并发现一些像IE 11这样的解决方案需要AttachEvent处理程序而不是js文件中的attach事件。但我不知道如何修改,因为我是js的新手。有人可以让我知道如何进行更改。

以下代码。

IEBrowserBot.prototype.modifySeparateTestWindowToDetectPageLoads = function(windowObject) {
    this.pageUnloading = false;
    var self = this;
    var pageUnloadDetector = function() {
        self.pageUnloading = true;
    };
    windowObject.attachEvent("onbeforeunload", pageUnloadDetector);
    BrowserBot.prototype.modifySeparateTestWindowToDetectPageLoads.call(this, windowObject);
};   

IEBrowserBot.prototype._fireEventOnElement = function(eventType, element, clientX, clientY) {
    var win = this.getCurrentWindow();
    triggerEvent(element, 'focus', false);

var wasChecked = element.checked;

// Set a flag that records if the page will unload - this isn't always accurate, because
// <a href="javascript:alert('foo'):"> triggers the onbeforeunload event, even thought the page won't unload
var pageUnloading = false;
var pageUnloadDetector = function() {
    pageUnloading = true;
};
win.attachEvent("onbeforeunload", pageUnloadDetector);
this._modifyElementTarget(element);
if (element[eventType]) {
    element[eventType]();
}
else {
    this.browserbot.triggerMouseEvent(element, eventType, true, clientX, clientY);
}


// If the page is going to unload - still attempt to fire any subsequent events.
// However, we can't guarantee that the page won't unload half way through, so we need to handle exceptions.
try {
    win.detachEvent("onbeforeunload", pageUnloadDetector);

    if (this._windowClosed(win)) {
        return;
    }

0 个答案:

没有答案