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

ProtocolException: Could not find node with given id during wait_for, page navigation #76

Open
mkofdwu opened this issue Feb 18, 2025 · 0 comments

Comments

@mkofdwu
Copy link

mkofdwu commented Feb 18, 2025

When using tab.wait_for during page navigation, this error occurs occasionally. (happens once every ~10 runs)

Traceback (most recent call last):
  File "/home/mkofdwu/domagent_test.py", line 19, in <module>
    asyncio.run(main())
    ~~~~~~~~~~~^^^^^^^^
  File "/usr/lib64/python3.13/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/usr/lib64/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/lib64/python3.13/asyncio/base_events.py", line 721, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/home/mkofdwu/domagent_test.py", line 16, in main
    el = await page.wait_for('#APjFqb')
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mkofdwu/.local/lib/python3.13/site-packages/zendriver/core/tab.py", line 1131, in wait_for
    item = await self.query_selector(selector)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mkofdwu/.local/lib/python3.13/site-packages/zendriver/core/tab.py", line 459, in query_selector
    node_id = await self.send(cdp.dom.query_selector(doc.node_id, selector))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mkofdwu/.local/lib/python3.13/site-packages/zendriver/core/connection.py", line 481, in send
    raise e
  File "/home/mkofdwu/.local/lib/python3.13/site-packages/zendriver/core/connection.py", line 477, in send
    return await tx
           ^^^^^^^^
zendriver.core.connection.ProtocolException: Could not find node with given id
command:DOM.querySelector
params:{'nodeId': NodeId(1), 'selector': '#APjFqb'} [code: -32000]

Example code:

import zendriver as zd
from zendriver import cdp
import asyncio

async def main():
    browser = await zd.start()
    page = await browser.get('http://localhost:8000/')

    el = await page.wait_for('#APjFqb')
    print(el)

asyncio.run(main())
from flask import Flask

app = Flask(__name__)

@app.get('/')
def index():
    return '<script>setTimeout(() => { location.replace("https://google.com") }, 2000)</script>'

app.run(port=8000)

It seems that every time this error is raised disable_dom_agent also fails, presumably because the dom agent is already disabled. This might also be the same reason why the node with id 1 doesn't exist. Im guessing that the dom agent is disabled during navigation for unknown reasons (?).

Commenting out the raise statement at https://github.com/stephanlensky/zendriver/blob/main/zendriver/core/tab.py#L476, wait_for returns the element as expected. I'm not sure what was the intention with disabling the dom agent and re-raising the error.

I'm using the latest version 0.5.1, on fedora workstation 41.

Thanks!

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

1 participant