capybara-webkit/src/capybara.js

40 lines
1.0 KiB
JavaScript
Raw Normal View History

Capybara = {
nextIndex: 0,
nodes: {},
invoke: function () {
return this[CapybaraInvocation.functionName].apply(this, CapybaraInvocation.arguments);
},
find: function (xpath) {
var iterator = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
var node;
var results = [];
while (node = iterator.iterateNext()) {
this.nextIndex++;
this.nodes[this.nextIndex] = node;
results.push(this.nextIndex);
}
return results.join(",");
},
text: function (index) {
return this.nodes[index].innerText;
},
attribute: function (index, name) {
return this.nodes[index].getAttribute(name);
2011-02-26 19:55:40 +00:00
},
tagName: function(index) {
2011-02-26 20:04:34 +00:00
return this.nodes[index].tagName.toLowerCase();
2011-02-26 20:18:11 +00:00
},
click: function (index) {
var clickEvent = document.createEvent('MouseEvents');
clickEvent.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
this.nodes[index].dispatchEvent(clickEvent);
}
};