Skip to content

Commit

Permalink
add elements() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Sarin committed May 5, 2012
1 parent e4a2971 commit 1862df3
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,48 @@ webdriver.prototype.elementByName = function(value, cb) {
this.element('name', value, cb);
};

webdriver.prototype.elements = function(using, value, cb) {
var _this = this;

var req = http.request(
_this.getOpts({url:'/elements'}), function(res) {
res.setEncoding('utf8');

var data = "";
res.on('data', function(chunk) { data += chunk.toString(); });
res.on('end', function() {
try{
var obj = JSON.parse(strip(data));
} catch (e) {
return cb ('Not JSON response', data)
}
if (obj.status > 0) {
cb(obj, null);
} else {
cb(null, obj.value);
}
});
});

req.write(JSON.stringify({
using : using,
value : value
}));
req.end();
};

webdriver.prototype.elementsByLinkText = function(value, cb) {
this.elements('link text', value, cb);
};

webdriver.prototype.elementsById = function(value, cb) {
this.elements('id', value, cb);
};

webdriver.prototype.elementsByName = function(value, cb) {
this.elements('name', value, cb);
};

webdriver.prototype.elementByCss = function(value, cb) {
this.element('css selector', value, cb);
};
Expand Down

0 comments on commit 1862df3

Please sign in to comment.