Skip to content

Instantly share code, notes, and snippets.

@artjomb
Created November 7, 2014 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save artjomb/f88a8d2935b6399d181a to your computer and use it in GitHub Desktop.
Save artjomb/f88a8d2935b6399d181a to your computer and use it in GitHub Desktop.
var casper = require('casper').create();
casper.selectOptionByText = function(selector, textToMatch){
this.evaluate(function(selector, textToMatch){
var select = document.querySelector(selector),
found = false;
Array.prototype.forEach.call(select.children, function(opt, i){
if (!found && opt.innerHTML.indexOf(textToMatch) !== -1) {
select.selectedIndex = i;
}
});
}, selector, textToMatch);
};
casper.start('http://stackoverflow.com/contact', function() {
this.selectOptionByText("#topic", "quality");
});
casper.run(function(){
this.capture("contact.png");
this.echo("DONE");
this.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment