Although you probably have an XPath syntax error, you should be aware that you cannot return DOM elements from the closure passed to the evaluate() method; you need to convert the NodeList and HTMLelement to some native Javascript types, for example. Arrays, objects, strings, etc.
In addition, there is a convenient method getElementsByXPath() in the ClientUtils module , which you can use from the __utils__ instance, which is automatically entered on each page, load:
casper.then(function() { if (this.fetchText('.statusMessageContainer').match(/Sorry, the file did not pass validation. Please review the validation errors in the report below/)) { this.echo("Upload failed!", "ERROR"); var errors = this.evaluate(function() { var errorRows = __utils__.getElementsByXPath('//table[@id="uploadTable"]/tr[position()>1]'); return Array.prototype.map.call(errorRows, function(e) { return e.innerText;
You can also use the ClientUtils Client Booklet to test your selectors directly in your browser console. For example, here click the bookmarklet and do this in the js console:
__utils__.getElementsByXPath('//table[@id="uploadTable"]/tr[position()>1]')
Then you will see if your selector is correct (it works on my side - I mean that it is syntactically correct).
Niko
source share