-
-
Save artjomb/f88a8d2935b6399d181a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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