I cannot figure out why the crawler is not able to find the element. It's a simple element...
I have tried running $client->refreshCrawler()
The website is very JS and AJAX heavy so I was wondering if maybe the content is somehow in a hidden DOM if that is at all possible?
I noticed when inspecting the a tag that there is an event and that has 'DOM2' next to it
These are all the attempts i've tested:
try {
echo " 1 - Finding region competitions\n";
echo $this->getCrawler()->filter('div[class="non-route race-button"]')->text();
} catch (Exception $e) {
echo "1 bad\n";
echo $e->getMessage()."\n";
}
try {
echo " 2 - Finding region competitions\n";
echo $this->getCrawler()->filter('div [class="non-route race-button"]')->text();
} catch (Exception $e) {
echo "2 bad\n";
echo $e->getMessage()."\n";
}
try {
echo " 3 - Finding region competitions\n";
echo $this->getCrawler()->filter('div[class=".non-route race-button"]')->text();
} catch (Exception $e) {
echo "3 bad\n";
echo $e->getMessage()."\n";
}
try {
echo " 4 - Finding region competitions\n";
echo $this->getCrawler()->filter('div [class=".non-route race-button"]')->text();
} catch (Exception $e) {
echo "4 bad\n";
echo $e->getMessage()."\n";
}
try {
echo " 5 - Finding region competitions\n";
$a = $this->getCrawler()->findElements(\Facebook\WebDriver\WebDriverBy::className('non-route race-button'));
echo "NUM: ".count($a)."\n";
} catch (Exception $e) {
echo "5 bad\n";
echo $e->getMessage()."\n";
}
try {
echo " 6 - Finding region competitions\n";
$b = $this->getCrawler()->findElements(\Facebook\WebDriver\WebDriverBy::className('.non-route race-button'));
echo "NUM: ".count($b)."\n";
} catch (Exception $e) {
echo "6 bad\n";
echo $e->getMessage()."\n";
}
try {
echo " 7 - Finding region competitions\n";
$c = $this->getCrawler()->findElements(\Facebook\WebDriver\WebDriverBy::tagName('data-test'));
} catch (Exception $e) {
echo "7 bad\n";
echo $e->getMessage()."\n";
}
try {
echo " 8 - Finding region competitions\n";
$d = $this->getCrawler()->findElements(\Facebook\WebDriver\WebDriverBy::linkText('All Races'));
echo "NUM: ".count($d)."\n";
} catch (Exception $e) {
echo "8 bad\n";
echo $e->getMessage()."\n";
}
try {
echo " 9 - Finding region competitions\n";
return $this->getCrawler()->selectLink('All Races')->link();
} catch (Exception $e) {
echo "9 bad\n";
echo $e->getMessage()."\n";
}
try {
echo " 10 - Finding region competitions\n";
$this->getCrawler()->filterXPath('/html/body/div[5]/div[1]/div[1]/div/div[4]/div/div/main/div[2]/div[2]/div/div/div/div[5]/section[1]/div/div/div[1]/div[2]/a')->click();
} catch (Exception $e) {
echo "10 bad\n";
echo $e->getMessage()."\n";
}
But each one returns The current node list is empty
I wasn't waiting long enough for the DOM to update
I used
sleep(3);
before trying to access the element and it now works OK