PhantomJs wait for ajax Request

2

I'm here with an immense difficulty in PhantomJS; Come on since yesterday I'm trying to automate the denatran process inside a system. How will this work? I already have the user's CPF and RENAVAN, I have a script done with an API that solves the captcha.

Let's go to the problem, I have to execute the script when putting the user data, after that solve the captcha that will return the json data (php file) and then put that return in the input and submit the form. >

var page = require('webpage').create();
var system = require('system');
var url = 'http://denatran.serpro.gov.br/certificado/veiculo.asp';

page.open(url, function (status) {
    page.includeJs('https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js', function () {
        page.onLoadFinished = function () {
            page.render("after_submit.png");
        };

        page.evaluate(function () {
            var image = $('#img_captcha_serpro_gov_br').attr('src');
            $("#txtCodRenavam").val('xxxxxxxxxxxx');
            $("#txtCPFCNPJ").val('xxxxxxxxxxxx');
            $.ajax({
                async: false, // this  
                cache: false,
                url: 'getCaptcha.php',
                type: 'post',
                dataType: "json",
                data: {image: image},
                success: function (data) {
                    $('#txtTexto_captcha_serpro_gov_br').val(data['captcha']);

                }
            });

        });

        page.render("before_submit.png");
        phantom.exit();
    });
});
    
asked by anonymous 20.06.2016 / 21:28

0 answers