The only thing I've got going for me is that the preceding <td>
will always have the same (and unique to the document) contents:
<td>
<label>unique text<label>
</td>
<td>dynamic text</td>
I can easily grab it with jQuery in the browser console (the page has jQuery loaded):
$("label:contains('unique text')").parent().next().text();
I've been at this for a while and have tried everything I can think of.
My most recent attempt was to use casperjs' evaluate and:
casper.thenEvaluate(function addID() {
$("label:contains('unique text')").parent().next().attr('id', 'uniqueID');
});
casper.then(function getText() {
var target = this.getHTML('td#uniqueID');
this.echo(target);
});
Which gives me:
CasperError: No element matching selector found: td#uniqueID
Why is my casper.thenEvaluate
function not creating the td#uniqueID
that I'm looking for?
If I do it like this post's answer:
casper.then(function getText() {
this.evaluate(function addID() {
$("label:contains('unique text')").parent().next().attr('id', 'uniqueID');
});
var target = this.thenEvaluate(function returnText() {
return $('#uniqueID').text();
});
this.echo(target);
});
I get an [Object Casper]
which seems to be exactly what it sounds like. It's filled with waitForContent
,scrollTo
, etc...
note: The above code block was incorrect (as was pointed out in this answer by Artjom B.) and was changed to this:
casper.then(function getText() {
this.evaluate(function addID() {
$("label:contains('unique text')").parent().next().attr('id', 'uniqueID');
});
var target = this.fetchText('#uniqueID');
this.echo(target);
});
The problem still persisted. See my answer below for the resolution.