pythonselenium-webdriverweb-scrapingxpathnodriver

How to search with xpath selector in "nodriver" on python


I am not sure about the correct way to search for specific items using XPath in nodriver on python.

I'm using this for try to select a button with a "confirm" text inside.

await tab.select("button[contains(text(),'confirm')]")

But i receive this output:

  File "XXXXXX", line 56
    totp_ig = await tab.select("button[contains(text(),'confirm')]")
  File "XXXXXX\lib\site-packages\nodriver\core\tab.py", line 242, in select
    return items
NameError: name 'items' is not defined

I only could search items with css selector like:

await tab.select(f"input[name=something]")

How can i search via xpath and not css?

Thanks.


Solution

  • You can use tab.find() to select a node using XPath. But you have to make sure your XPath is correct.

    await tab.find("//button[contains(text(),'confirm')]")
    

    Since your XPath is trying to select the element by text, you could just use the text to find the element.

    await tab.find("confirm")