Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions zendriver/core/tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,17 @@ async def xpath(self, xpath: str, timeout: float = 2.5) -> List[Element]: # noq
items: List[Element] = []
try:
await self.send(cdp.dom.enable(), True)
items = await self.find_all(xpath, timeout=0)
if not items:
loop = asyncio.get_running_loop()
loop = asyncio.get_running_loop()
while not items:
start_time = loop.time()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is merged already, but shouldn't the start_time = loop.time() be outside of the while loop? Did I misunderstand the change?
I would also merge the await self.sleep(0.1) into the find_all call.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original implementation may have been copied directly from nodriver, bugs included.

Definitely feel free to PR some fixes :)

while not items:
try:
items = await self.find_all(xpath, timeout=0)
await self.sleep(0.1)
if loop.time() - start_time > timeout:
break
except Exception:
pass

await self.sleep(0.1)
if loop.time() - start_time > timeout:
break
finally:
await self.disable_dom_agent()
return items
Expand Down