FriendsOfPHP / Goutte

Goutte, a simple PHP Web Scraper
MIT License
9.26k stars 1.01k forks source link

How to click an empty space in Goutte? #439

Closed LindaM2021 closed 3 years ago

LindaM2021 commented 3 years ago

The original document says; do that to click a link:

$crawler = $client->click($crawler->selectLink('Sign in')->link());

However, the area I would like to click is something like the code below. There is no text.. In the browser, you can only see an icon.

<div id="Wrap" class="IconWrap">
    <span class="Icon">&nbsp;</span>
</div>

I would be grateful if you have any idea.

stof commented 3 years ago

select your element with another method than selectLink. For instance, you could find in the crawler by a CSS selector instead. You have the whole API of symfony/dom-crawler available here.

LindaM2021 commented 3 years ago

I was able to reach the elements by ->filter() function. The problem is that the click function is expecting a link object such as $crawler->filter('body > div > span')->link() and when I add ->link() it returns, Unable to navigate from a "span" tag error.