0

I want to fill input #searchForm with CasperJS

I tried 3 methods and only one works (the sendKeys method !)

var casper = require("casper").create({
    clientScripts: ["vendor/jquery.min.js"],
    verbose: false,
    logLevel: 'debug',
});
casper.waitForSelector('#search_field', function() {
    console.log('#search_field FOUND !!!');
    //document.querySelector('#search_field').value = 'search1'; //does not work
    //casper.sendKeys('#search_field', 'search1'); // works !
    //$('#search_field').val('search1'); // does not work

});

My preference would be to use jQuery to fill forms. Why don't the 2 other methods work?

2
  • Possible duplicate of Why doesn't plain JavaScript work in CasperJS? Commented Oct 18, 2016 at 19:40
  • 2
    Answer: because you need to put code that runs on the DOM into the page context (inside casper.evaluate). Commented Oct 18, 2016 at 19:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.