Created
April 12, 2012 06:50
-
-
Save firedfox/2365241 to your computer and use it in GitHub Desktop.
phantomjs googlegroup discussion - Click onto an image
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
<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> |
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 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