且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在PhantomJS中找不到变量:页面

更新时间:2023-11-21 16:13:58

非常确定在 page.evaluate 环境,你不能从Phantom脚本中引用任何东西。

Pretty sure that in a page.evaluate environment, you can't reference anything from the Phantom script.

在你的情况下,你实际上可以有多个评估调用:

In your case, you could actually have multiple evaluate calls:

console.log("Teste de Login");

var page = require('webpage').create();
page.open('http://localhost/login', function(status) {
    console.log("Page loadeed");

    if(status === "success") {
        page.render('example1.png');
    }

    page.evaluate(function() {
        // $("#numeroUsuario").val("99734167");
        document.getElementById('numeroUsuario').value = "99734167";
    });

    page.render('exampl2.png');

    page.evaluate(function() {
        // $("#formLogin").submit();
    });

    page.render('example3.png');

    phantom.exit();
});