如何通过 Python3 中的 Selenium 验证是否存在另一个页面

How to validate there is another page or not through Selenium in Python3

类似于这个问题 , I would like to achieve a similar thing on a different website (http://digesto.asamblea.gob.ni/consultas/coleccion/) python3 和 selenium。

我想让我的脚本检查 "next page" 箭头是否可点击。

这是我目前尝试过的(简化版):

try:
    driver.find_element_by_css_selector('li a[data_page*=next] and not a[onclick*="return false"]').click() # check if another page exists
    print("There is another page.")
except NoSuchElementException:
    print("No further page exist.")

在上述网站上,未激活箭头的源代码如下所示:

激活时看起来像:

但是,我似乎没有得到正确的 css 选择器路径。脚本告诉我没有第二页,尽管它存在。

@JeffC 的评论近乎完美,但有一个缺陷。您可以使用以下解决方案:

try:
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "li:not(.disabled)>a[data-page='next']"))).click()
    print("There is another page.")
except TimeoutException:
    print("No more pages")
    break