Sha256: 0380dafe4c7accc7934a60073379f61507d7416d88c94eb2924645606dfe9ba8

Contents?: true

Size: 1.94 KB

Versions: 9

Compression:

Stored size: 1.94 KB

Contents

// stolen from injectableSelenium.js in WebDriver
var browserbot = {
  createEventObject : function(element, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown) {
    var evt = element.ownerDocument.createEventObject();
        evt.shiftKey = shiftKeyDown;
        evt.metaKey = metaKeyDown;
        evt.altKey = altKeyDown;
        evt.ctrlKey = controlKeyDown;
        return evt;
    },

    triggerEvent: function(element, eventType, canBubble, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown) {
        canBubble = (typeof(canBubble) == undefined) ? true: canBubble;
        if (element.fireEvent && element.ownerDocument && element.ownerDocument.createEventObject) {
            // IE
            var evt = this.createEventObject(element, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown);
            element.fireEvent('on' + eventType, evt);
        } else {
            var evt = document.createEvent('HTMLEvents');

            try {
                evt.shiftKey = shiftKeyDown;
                evt.metaKey = metaKeyDown;
                evt.altKey = altKeyDown;
                evt.ctrlKey = controlKeyDown;
            } catch(e) {
                // Nothing sane to do
                }

            evt.initEvent(eventType, canBubble, true);
            return element.dispatchEvent(evt);
        }
    },

    getVisibleText: function() {
        var selection = getSelection();
        var range = document.createRange();
        range.selectNodeContents(document.documentElement);
        selection.addRange(range);
        var string = selection.toString();
        selection.removeAllRanges();

        return string;
    },

    getOuterHTML: function(element) {
        if (element.outerHTML) {
            return element.outerHTML;
        } else if (typeof(XMLSerializer) != undefined) {
            return new XMLSerializer().serializeToString(element);
        } else {
            throw "can't get outerHTML in this browser";
        }
    }


};

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
watir-webdriver-0.2.3 lib/watir-webdriver/browserbot.js
watir-webdriver-0.2.2 lib/watir-webdriver/browserbot.js
watir-webdriver-0.2.1 lib/watir-webdriver/browserbot.js
watir-webdriver-0.2.0 lib/watir-webdriver/browserbot.js
watir-webdriver-0.2.0.dev2 lib/watir-webdriver/browserbot.js
watir-webdriver-0.2.0.dev lib/watir-webdriver/browserbot.js
watir-webdriver-0.1.9 lib/watir-webdriver/browserbot.js
watir-webdriver-0.1.8 lib/watir-webdriver/browserbot.js
watir-webdriver-0.1.7 lib/watir-webdriver/browserbot.js