Skip to content

Commit 8009090

Browse files
committed
updates to the xpath
1 parent 4b3264d commit 8009090

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

zendriver/core/tab.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -382,21 +382,17 @@ async def xpath(self, xpath: str, timeout: float = 2.5) -> List[Element]: # noq
382382
:rtype:
383383
"""
384384
items: List[Element] = []
385-
try:
386-
await self.send(cdp.dom.enable(), True)
387-
loop = asyncio.get_running_loop()
388-
while not items:
389-
start_time = loop.time()
390-
try:
391-
items = await self.find_all(xpath, timeout=0)
392-
except TimeoutError:
393-
pass
394-
395-
await self.sleep(0.1)
396-
if loop.time() - start_time > timeout:
397-
break
398-
finally:
385+
loop = asyncio.get_running_loop()
386+
start_time = loop.time()
387+
388+
while (loop.time() - start_time) < timeout and len(items) == 0:
389+
try:
390+
await self.send(cdp.dom.enable(), True)
391+
items = await self.find_all(xpath, timeout=0)
392+
except Exception as e:
393+
pass # find_elements_by_text may raise exception
399394
await self.disable_dom_agent()
395+
400396
return items
401397

402398
async def get(

0 commit comments

Comments
 (0)