Skip to content

Instantly share code, notes, and snippets.

@jonleighton
Created November 2, 2011 23:03
Show Gist options
  • Save jonleighton/1335232 to your computer and use it in GitHub Desktop.
Save jonleighton/1335232 to your computer and use it in GitHub Desktop.
page = require('webpage').create()
page.content =
"<html>
<body>
<div id='foo' style='width: 100px; height: 400px;'></div>
</body>
</html>"
page.onConsoleMessage = (message) ->
console.log(message)
page.evaluate ->
document.onclick = (e) ->
console.log("#{e.pageX},#{e.pageY}")
page.viewportSize = { width: 100, height: 100 }
page.scrollPosition = { left: 0, top: 200 }
page.sendEvent('click', 0, 0)
# => Page receives click at 0,200
page.evaluate ->
document.getElementById('foo').style.height = '250px'
# => The current viewport position now extends 50px below the bottom of the page
page.sendEvent('click', 0, 0)
# => Page receives click at 0,166
phantom.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment