Skip to content

Commit d3f3bd2

Browse files
committed
check_and_click_next_page (Locator.count: Error: Can't query n-th element)
1 parent 2dd5c55 commit d3f3bd2

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

src/main.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,26 @@ async def check_and_click_next_page(page: Page) -> bool:
2525
selector = "a[title='Next page']"
2626
next_button = page.locator(selector).first
2727

28-
if await next_button.count() > 0:
29-
# Check if button is enabled (not disabled)
30-
is_disabled = await next_button.is_disabled()
31-
is_visible = await next_button.is_visible()
32-
33-
if not is_disabled and is_visible:
34-
logger.debug("Found enabled next page button with selector: %s", selector)
35-
await next_button.click()
36-
await page.wait_for_load_state()
37-
return True
38-
39-
logger.debug("Next page button found but disabled or not visible: %s", selector)
28+
if not next_button:
29+
logger.warning("No next page button found")
4030
return False
4131

42-
logger.warning("No next page button found")
43-
return False
32+
# Check if button is enabled (not disabled)
33+
is_disabled = await next_button.is_disabled()
34+
is_visible = await next_button.is_visible()
35+
36+
if is_disabled:
37+
logger.debug("Next page button found but disabled: %s", selector)
38+
return False
39+
40+
if not is_visible:
41+
logger.debug("Next page button found but not visible: %s", selector)
42+
return False
43+
44+
logger.debug("Found enabled next page button with selector: %s", selector)
45+
await next_button.click()
46+
await page.wait_for_load_state()
47+
return True
4448

4549
except TimeoutError as e:
4650
logger.warning("Error checking for next page button: %s", e)

0 commit comments

Comments
 (0)