Skip to content Skip to sidebar Skip to footer

Casperjs: How Do I Click A Remote Div And Then Update It's Class Name?

As a way of learning CasperJS, I am trying to initiate a click event on a div on a remote page, and then change the class name of the div after I have clicked it. The idea is to fi

Solution 1:

You're calling this.click within evaluate(), it just can't work as evaluate() executes code within the page DOM context where there's probably no window.click method.

Here's a possibly working script:

var linkSelector = 'div.clickable_div';

casper.then(function() {
    if (!this.exists(linkSelector)) return;
    this.click(linkSelector);
    this.evaluate(function(linkSelector) {
        __utils__.findOne(linkSelector).setAttribute("className", "clicked");
    }, linkSelector);
});

You may want to have better handling of errors and edge cases, but you get the idea.

Post a Comment for "Casperjs: How Do I Click A Remote Div And Then Update It's Class Name?"