Trying to fill table element by id with casperjs

38 Views Asked by At
casper.thenEvaluate(function(text){
    document.querySelector("#inputValue").value=text
})

casper.thenEvaluate seems to not accept the argument and it is filling undefined in the webpage.

2

There are 2 best solutions below

0
pheroMona13 On

According to the documentations you should use "thenEvaluate" after "start" like this:

// Querying for "Chuck Norris" on Google
casper.start('http://google.fr/').thenEvaluate(function(term) {
    document.querySelector('input[name="q"]').setAttribute('value', term);
    document.querySelector('form[name="f"]').submit();
}, 'Chuck Norris');

casper.run();

source:

http://docs.casperjs.org/en/latest/modules/casper.html#thenevaluate
0
Mario Nikolaus On

Since evaluate runs in browser context(instead of Casper one) you have to explicitly provide variables after the callback function definition. Please check example from the docs

casper.evaluate(function(username, password) {
  document.querySelector('#username').value = username;
  document.querySelector('#password').value = password;
  document.querySelector('#submit').click();
}, 'sheldon.cooper', 'b4z1ng4');

Note that username param in callback corresponds to sheldon.cooper and password param corresponds to b4z1ng4.