Last active
June 18, 2018 13:47
-
-
Save mlconnor/3933381 to your computer and use it in GitHub Desktop.
Get all links with Selenium in PHP
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
require_once "phpwebdriver/WebDriver.php"; | |
$webdriver = new WebDriver("localhost", "4444"); | |
$webdriver->connect("firefox"); | |
$webdriver->get("http://slashdot.org"); | |
$links = $webdriver->findElementsBy(LocatorStrategy::tagName, "a"); | |
$getLinksScript = <<<EOT | |
var linkTags = document.getElementsByTagName('a'); | |
var links = []; | |
for ( var i = 0; i < linkTags.length; i++ ) { | |
var href = linkTags[i].href; | |
if ( href ) { | |
links.push(href); | |
} | |
} | |
return links; | |
EOT; | |
$href = $webdriver->executeScript($getLinksScript, array()); | |
print_r($hrefs); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how about this?