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

Looping over querySelectorAll results and performing actions throws Uncaught DomException: -32000 - Could not find node with given id #594

Open
sanderdlm opened this issue Jan 7, 2024 · 0 comments

Comments

@sanderdlm
Copy link
Contributor

sanderdlm commented Jan 7, 2024

Sorry for the long yet vague title.

I've included a short reproducer:

<?php

use HeadlessChromium\BrowserFactory;
use HeadlessChromium\Dom\Node;

require_once __DIR__ . '/vendor/autoload.php';

$browserFactory = new BrowserFactory();

$browser = $browserFactory->createBrowser([
    'headless' => false
]);

$page = $browser->getPages()[0];

$page->navigate('https://www.bergfreunde.eu/la-sportiva-testarossa-climbing-shoes/')->waitForNavigation();

$sizeOptions = $page->dom()->querySelectorAll('ul.varlist-select-size li');

/** @var Node $option */
foreach ($sizeOptions as $option) {
    $size = trim($option->getText());
    echo "Checking size $size\n";

    $mainPrice = $page->dom()->querySelector('[data-codecept="productPrice"]')->getText();
    echo "Main price: $mainPrice\n";
}

If I loop over my list of li items, and only print the content with getText(), the code runs fine.
If I loop over my list of li items, and only print the content of a random div somewhere else on the tab, the code runs fine.
But if I try to do both, I get the following error (after 1 run of the loop, so second pass):

PHP Fatal error:  Uncaught HeadlessChromium\Exception\DomException: -32000 - Could not find node with given id in /Users/marc434451/Sites/personal/shooz/vendor/chrome-php/chrome/src/Dom/Node.php:214
Stack trace:
#0 /Users/marc434451/Sites/personal/shooz/vendor/chrome-php/chrome/src/Dom/Node.php(138): HeadlessChromium\Dom\Node->assertNotError(Object(HeadlessChromium\Communication\Response))
#1 /Users/marc434451/Sites/personal/shooz/vendor/chrome-php/chrome/src/Dom/Node.php(156): HeadlessChromium\Dom\Node->getHTML()
#2 /Users/marc434451/Sites/personal/shooz/repro.php(22): HeadlessChromium\Dom\Node->getText()
#3 {main}
  thrown in /Users/marc434451/Sites/personal/shooz/vendor/chrome-php/chrome/src/Dom/Node.php on line 214

Probably just interacting with the nodes in a wrong way/order, but I couldn't find any info in the docs.

@sanderdlm sanderdlm changed the title Looping over list of elements from querySelectorAll and performing actions sometimes throws Uncaught HeadlessChromium\Exception\DomException: -32000 - Could not find node with given id Looping over querySelectorAll results and performing actions throws Uncaught DomException: -32000 - Could not find node with given id Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant