Phantomjs Wait for ajax Request

Asked

Viewed 134 times

2

I am here with a huge difficulty in Phantomjs; We go there since yesterday I am trying to automate the process of Natran within a system. How will it work? I already have the user’s CPF and RENAVAN, I have a script made with an API that solves captcha.

Let’s get to the problem, I have to when running the script put the user data, after that solve the captcha that will return the json data (php file) and then put this 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();
    });
});
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.