Skip to content

Instantly share code, notes, and snippets.

@firedfox
Created April 12, 2012 06:50
Show Gist options
  • Save firedfox/2365241 to your computer and use it in GitHub Desktop.
Save firedfox/2365241 to your computer and use it in GitHub Desktop.
phantomjs googlegroup discussion - Click onto an image
<html>
<body>
<table width="251" cellspacing="0" cellpadding="0" align="left" valign="bottom">
<tr>
<td>
<div id="show_cart">
<a href="next.htm">
<img src="cart.png" border="0" width="251" height="71">
</a>
</div>
</td>
</tr>
</table>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</body>
</html>
var page = require('webpage').create();
page.onConsoleMessage = function(msg) { console.log(msg); };
page.onLoadFinished = function() {
var offset = page.evaluate(function() {
console.log('url:', location.href);
if (typeof $ != 'undefined') {
return $('#show_cart > a >img').offset();
}
});
if (offset) {
page.sendEvent('click', offset.left + 1, offset.top + 1);
} else {
phantom.exit();
}
};
page.open("http://127.0.0.1/~danny/test.html");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment