J
J
Julia Kovalenko2016-09-15 11:01:11
JavaScript
Julia Kovalenko, 2016-09-15 11:01:11

How to wait for the page to load in phantomJs?

I open the page. It has an authorization form. I fill it in and do submit(). A button with id='install_allow' appears in the same window, which I need to click on. At me it turned out to make only with use of a timeout. How to do it without it?
Here it works:

page_get_code.open(url_get_code, function (status) {
    page_get_code.evaluate(function(login, passwd) {
        document.querySelector("input[name=email]").value = login;
        document.querySelector("input[name=pass]").value = passwd;
        document.querySelector("#login_submit").submit();
    }, login, passwd);

    setTimeout(function(){
        page_get_code.evaluate(function() {
            document.querySelector("#install_allow").click();
        });
    }, 3000);
});

I tried to do this, but the Install_allow button is not pressed:
page_get_code.open(url_get_code, function (status) {
    page_get_code.evaluate(function(login, passwd) {
        document.querySelector("input[name=email]").value = login;
        document.querySelector("input[name=pass]").value = passwd;
        document.querySelector("#login_submit").submit();
    }, login, passwd);

    page_get_code.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
        page_get_code.evaluate(function() {
            $( document ).ready(function(){
                $("#install_allow").click();
            });
        });
    });
});

I tried to do it through the onLoadFinished event, but it didn't work either.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
Julia Kovalenko, 2016-09-15
@kovalenko_jul_s

var count_load = 0;
page_get_code.onLoadFinished = function(status) {
    count_load++;
    if(count_load == 2){
        page_get_code.evaluate(function() {
            if(document.getElementById("install_allow")){
                document.getElementById("install_allow").click();
            }
        });
    }
};

A
Alexander Aksentiev, 2016-09-15
@Sanasol

https://github.com/search?l=javascript&q=install_a...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question