Created
October 9, 2012 00:33
-
-
Save pilate/3855832 to your computer and use it in GitHub Desktop.
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 root_url = "http://www.mailinator.com/"; | |
| // Create new WebPage object for browsing | |
| var page = new WebPage(); | |
| // Repeat console.log messages from PhantomJS | |
| page.onConsoleMessage = function (msg) { | |
| console.log(msg); | |
| }; | |
| // Callback for each page onload | |
| page.onLoadFinished = function (msg) { | |
| // Get URL of finished page | |
| var url = page.evaluate(function () { return window.location.toString(); }); | |
| // Handle original URL | |
| if (url === root_url) { | |
| page.evaluate(function () { | |
| // Populate login form and submit | |
| document.getElementById("check_inbox_field").value = "phantomjs"; | |
| document.forms['search'].submit(); | |
| }); | |
| } | |
| // Check for inbox URL | |
| else if (url.indexOf("maildir") !== -1) { | |
| page.evaluate(function () { | |
| // Find the "Alternate Email" font tag | |
| var smalls = document.getElementsByClassName("small"); | |
| for (var i=0; i<smalls.length; i++) { | |
| var fonts = smalls[i].getElementsByTagName("font"); | |
| if (fonts.length) { | |
| // Log when we find it | |
| console.log("Alternate Email:", fonts[0].innerHTML); | |
| break; | |
| } | |
| } | |
| }); | |
| // Exit after the inbox loads | |
| phantom.exit(); | |
| } | |
| }; | |
| // Browse to url | |
| page.open(root_url); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment