1

When l use

this.click("#menuContainer > div > ul > li.menu_item_219 > a");

It works! But when l use this code in this.evaluate(function(){});

document.querySelector("#menuContainer > div > ul > li.menu_item_219 > a").click();

It does not work. Here is the code:

    phantom.outputEncoding="GBK";

    var casper = require("casper").create({
    verbose: true,
    logLevel: 'info',
    clientScripts:  [
        'G:/Web/jquery-2.1.4.min.js'
    ],
    pageSettings: {
        loadImages: false,
        loadPlugins: false,
        userAgent: "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36"
    }

});
casper.options.waitTimeout = 100000;

casper.start("http://qzone.qq.com/");

casper.then(function(){

    this.page.switchToChildFrame(0);
    this.fill('form#loginform',{
        'u':"myusername",
        'p':"mypassword"
    },false);
    this.echo("filled");
});
casper.then(function(){

    this.click('input[id="login_button"]');
});

casper.waitForSelector('a#tab_menu_care',function(){

    this.click("#menuContainer > div > ul > li.menu_item_219 > a");

    //DO NOT WORKING!
    // this.evaluate(function(){
    //  var a = document.querySelector("#menuContainer > div > ul > li.menu_item_219 > a");
    //  __utils__.echo(a);
    //  a.click();
    // });

});
casper.wait(5000,function(){
    this.capture("after-click.png");
    this.echo(this.getCurrentUrl());
 });
casper.run();

l capture the "after-click.png" to see if it works. Is there anything wrong with my code?l had search for answer whole day on stackoverflow but nothing is uesful_(:з」∠)_ Hope someone can help me !

0 Answers0