Skip to content

Instantly share code, notes, and snippets.

Created June 21, 2013 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5828718 to your computer and use it in GitHub Desktop.
Save anonymous/5828718 to your computer and use it in GitHub Desktop.
var page = require('webpage').create(),
url = 'http://localhost:1134/test_client.html';
//Visit the specified url
page.open(url, function (status) {
check(step1);
});
//Fill in the command and click 'Go!'
function step1(){
page.evaluate(function() {
document.getElementsByName('command')[0].value = 'whoami';
document.getElementById('execute').click();
});
check(step2);
}
//Log the output
function step2(){
page.evaluate(function() {
console.log(document.getElementById('output').innerHTML);
});
phantom.exit();
}
//Check and wait for the 'Go!' button to be enabled
function check(step){
state = page.evaluate(function() {
return document.getElementById('execute').getAttribute('aria-disabled') == "false" && document.getElementById('output').innerHTML !='';
});
if(!state)
setTimeout(function(){
check(step);
},50);
else
step();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment