Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html() function of the DomCrawler doesn't returning anything after calling filter function #478

Open
gabrielspiteri-highlight opened this issue Jun 15, 2021 · 8 comments

Comments

@gabrielspiteri-highlight

We have noticed a change of behaviour since upgrading to chrome v91 as our client. The html function has an odd behaviour.

The below returns the html correctly:

dump($client->getCrawler()->html());

But then after appling a filter the html function always returns an empty string.

$client->getCrawler()->filter("table.statistic-table thead th")->each(
function (Crawler $tr) use (&$headers) {
dump($tr->html());
});

Anyone else is experiencing this? We have had to mitigate this by calling the text function instead. But that itself presents another problem because when the text is hidden in a scrollable section, the text function also returns and empty string.

@Boschman
Copy link

I'm experiencing the exact same problem since Chrome 91.

Have you found any workarounds?

@LoicBoursin
Copy link

I have the same issue. On my computer, tests are working because I have an older Chrome version. But when testing on GitHub Actions, filter + html returns empty.

@jbalatero
Copy link

Encountered this issue as well

@MartinsPaulo
Copy link

I also encounter this problem.

@Boschman
Copy link

Any news on this issue? How are people able to still use the DomCrawler with this problem? For me unfortunately Panther became practically useless.

@Boschman
Copy link

It's not a bug, it's a feature... I did some research and found a solution!

ChromeDriver 91 (and up) became compliant with the W3C standard regarding the "Get Element Attribute". That's nice, but unfortunately this breaks our tests. But: there's a simple solution. ChromeDriver only follows this W3C standard when the driver is in W3C mode. By disabling that mode Panther will work as before.

This will do the trick:

use Facebook\WebDriver\Chrome\ChromeOptions;

$chromeOptions = new ChromeOptions();
$chromeOptions->setExperimentalOption('w3c', false);

$this->client = static::createPantherClient([], [],
    [
        'capabilities' => [
            ChromeOptions::CAPABILITY => $chromeOptions,
        ],
    ]);

@eualexey
Copy link

It's not a bug, it's a feature... I did some research and found a solution!

ChromeDriver 91 (and up) became compliant with the W3C standard regarding the "Get Element Attribute". That's nice, but unfortunately this breaks our tests. But: there's a simple solution. ChromeDriver only follows this W3C standard when the driver is in W3C mode. By disabling that mode Panther will work as before.

This will do the trick:

use Facebook\WebDriver\Chrome\ChromeOptions;

$chromeOptions = new ChromeOptions();
$chromeOptions->setExperimentalOption('w3c', false);

$this->client = static::createPantherClient([], [],
    [
        'capabilities' => [
            ChromeOptions::CAPABILITY => $chromeOptions,
        ],
    ]);

Guys help me please where should I put above mentioned code in my code so I could fetch only data I need

<?php

use Symfony\Component\Panther\Client;
require 'vendor/autoload.php'; 
try {
    
    $client = Client::createChromeClient();
    $client->request('GET', 'https://websitename.com'); 
    $html = $client->getCrawler()->filter('div.options')->html();
    print_r($html);
....

Thank you!

@melkamar
Copy link

Into where you are initializing the client

$client = Client::createChromeClient([], [], [
        'capabilities' => [
            ChromeOptions::CAPABILITY => $chromeOptions,
        ],
    ]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants