1

Analogous to this question Selenium - How to know if next page doesn't exist?, I would like to achieve a similar thing on a different website (http://digesto.asamblea.gob.ni/consultas/coleccion/) with python3 and selenium.

I would like to have my script check whether the "next page" arrow is clickable or not.

This is what I have tried so far (simplified):

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.")

On the above mentioned website, the source code for an inactive arrow looks like this:

enter image description here

while active it looks like:

enter image description here

However, it seems that I did not get the css selector path correct. The script tells me that there is not second page, although it exist.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Til Hund
  • 1,543
  • 5
  • 21
  • 37

1 Answers1

1

@JeffC's comment was near perfect but had a defect. You can use the following solution:

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
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352