Commit 3787e0af 3787e0afc40993cf0b2360970f4ce61c896063b5 by Nicolas Perriault

fixes #438 - getElementAttribute to works with XPath

1 parent 9019a73a
......@@ -892,7 +892,7 @@ Casper.prototype.getElementAttr = function getElementAttr(selector, attribute) {
"use strict";
this.checkStarted();
return this.evaluate(function _evaluate(selector, attribute) {
return document.querySelector(selector).getAttribute(attribute);
return __utils__.findOne(selector).getAttribute(attribute);
}, selector, attribute);
};
......
/*global casper*/
/*jshint strict:false*/
casper.test.begin('getElementAttribute() tests', 1, function(test) {
var x = require('casper').selectXPath;
casper.test.begin('getElementAttribute() tests', 2, function(test) {
casper.start('tests/site/elementattribute.html', function() {
test.assertEquals(this.getElementAttribute('.testo','data-stuff'), 'beautiful string',
'Casper.getElementAttribute() works as intended');
test.assertEquals(this.getElementAttribute('.testo', 'data-stuff'),
'beautiful string', 'Casper.getElementAttribute() works with a CSS selector');
test.assertEquals(this.getElementAttribute(x('//div[@class]'), 'data-stuff'),
'beautiful string', 'Casper.getElementAttribute() works with a XPath selector');
}).run(function() {
test.done();
});
......