Created
February 14, 2012 23:55
-
-
Save n1k0/1831787 to your computer and use it in GitHub Desktop.
Casper script
This file contains hidden or 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
$ casperjs event.js | |
[info] [phantom] Starting... | |
[info] [phantom] Running suite: 3 steps | |
[debug] [phantom] Successfully injected Casper client-side utilities | |
[info] [phantom] Step 2/3 file:///Users/niko/Sites/casperjs/test.html (HTTP 0) | |
[debug] [phantom] start page is loaded | |
[info] [phantom] Step 2/3: done in 207ms. | |
[info] [phantom] Step 3/3 file:///Users/niko/Sites/casperjs/test.html (HTTP 0) | |
[info] [phantom] Step 3/3: done in 310ms. | |
[info] [phantom] Done 3 steps in 406ms | |
[info] [remote] __event | |
A click occured! |
This file contains hidden or 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
<!doctype html> | |
<html> | |
<head> | |
<title>Hey.</title> | |
<script type="text/javascript"> | |
function simulateClick(selector) { | |
var evt = document.createEvent("MouseEvents"); | |
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); | |
var cb = document.querySelector(selector); | |
cb.dispatchEvent(evt) | |
console.log('clicked') | |
} | |
setTimeout(function() { | |
simulateClick("input"); | |
}, 1000); | |
</script> | |
</head> | |
<body> | |
<h1>Hello</h1> | |
<input type="checkbox"/> | |
</body> | |
</html> |
This file contains hidden or 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({ | |
verbose: true, | |
logLevel: "debug" | |
}); | |
var url = 'file://' + require('fs').workingDirectory + '/test.html'; | |
casper.on('remote.message', function(message) { | |
if (message === "__event") { | |
this.echo('A click occured!').exit(); | |
} | |
}); | |
casper.start(url).thenEvaluate(function() { | |
var onclick = function(evt) { | |
console.log('__event'); | |
}; | |
window.addEventListener("click", onclick, true); | |
}); | |
casper.run(function(){}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment