Поиск по блогу

воскресенье, 17 мая 2015 г.

Постигаем азы с видео "Automation with PhantomJS "

Здесь я набрал код из видео... и решил, что из этого примера надо запомнить приемы if(system.args.length - проверки количества аргументов в строке запуска, document.getElementById("firstname").value ="Joe"; - (пере)присвоения значений полям, setTimeout(function(){phantom.exit()}, 400)

In [ ]:
var page = new WebPage(),
    system = require('system'),
    address
    
if(system.args.length <2){
    console.log("You need an address")
    phantom.exit()
} 
else {
    address = system.args[1];
    page.open(address, function(stattus){
        if(status==="success"){
            page.evaluate(function(){
                document.getElementById("firstname").value ="Joe";
                document.getElementById("lastname").value ="Joe";
                document.getElementById("email").value ="Joe";
                document.getElementById("frm").value ="Joe";
            });
            setTimeout(function(){phantom.exit()}, 400) 
        } 
    })

}
In [ ]:
 


Посты чуть ниже также могут вас заинтересовать

Комментариев нет:

Отправить комментарий