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

[NODRIVER] NameError: name 'items' is not defined in async select method #2122

Open
khamaileon opened this issue Jan 22, 2025 · 2 comments
Open

Comments

@khamaileon
Copy link

Description:
When using the select method, a NameError is raised:

NameError: name 'items' is not defined. Did you mean: 'item'?
  async def select(
      self,
      selector: str,
      timeout: Union[int, float] = 10,
  ) -> nodriver.Element:
      """
      find single element by css selector.
      can also be used to wait for such element to appear.

      :param selector: css selector, eg a[href], button[class*=close], a > img[src]
      :type selector: str

      :param timeout: raise timeout exception when after this many seconds nothing is found.
      :type timeout: float,int

      """
      loop = asyncio.get_running_loop()
      start_time = loop.time()

      selector = selector.strip()
      item = await self.query_selector(selector)

      while not item:
          await self
          item = await self.query_selector(selector)
          if loop.time() - start_time > timeout:
              return items
          await self.sleep(0.5)
      return item

Steps to Reproduce:

  1. Call the select method with a CSS selector and a timeout value.
  2. Ensure that no matching element appears within the timeout period.
  3. Observe the NameError when the return items line is executed.

Expected Behavior:
The method should raise an appropriate exception if no matching element is found within the timeout period.

Actual Behavior:
The method raises a NameError because the variable items is not defined.

@khamaileon khamaileon changed the title NameError: name 'items' is not defined in async select method [NODRIVER] NameError: name 'items' is not defined in async select method Jan 25, 2025
@stephanlensky
Copy link

Hey @khamaileon, I created a fork of nodriver here stephanlensky/zendriver which fixes this and other bugs, feel free to take a look.

@khamaileon
Copy link
Author

I can confirm that the problem is resolved with Zendriver.

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

3 participants
@khamaileon @stephanlensky and others