title: Selenium clicking to next page until on last page
body: <p>I am trying to keep clicking to next page on this <a href="https://claimittexas.org/app/claim-search" rel="nofollow noreferrer">website</a>, each time appending the table data to a csv file and then when I reach the last page, append the table data and break the while loop</p>
  
  <p>Unfortunately, for some reason it keeps staying on the last page, and I have tried several different methods to catch the error</p>
  
  <pre><code>while True:
    try :
        WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, 'Next'))).click()
    except :
        print("No more pages left")
        break
  driver.quit()
  </code></pre>
  
  <p>I also tried this one:</p>
  
  <pre><code>try:
      link = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR,'.pagination-next a')))
      driver.execute_script('arguments[0].scrollIntoView();', link)
      link.click()
  except:
      keep_going = False
  </code></pre>
  
  <p>I've tried putting print statements in and it just keeps staying on the last page.</p>
  
  <p>Here is the HTML for the first page/last page for the next button, I'm not sure if I could do something utilizing this: 
  HTML for first page:</p>
  
  <pre><code>&lt;li role="menuitem" ng-if="::directionLinks" ng-class="{disabled: noNext()||ngDisabled}" class="pagination-next" style=""&gt;&lt;a href="" ng-click="selectPage(page + 1, $event)" ng-disabled="noNext()||ngDisabled" uib-tabindex-toggle=""&gt;Next&lt;/a&gt;&lt;/li&gt;
      &lt;a href="" ng-click="selectPage(page + 1, $event)" ng-disabled="noNext()||ngDisabled" uib-tabindex-toggle=""&gt;Next&lt;/a&gt;
  &lt;/li&gt;
  </code></pre>
  
  <p>HTML for last page:</p>
  
  <pre><code>&lt;li role="menuitem" ng-if="::directionLinks" ng-class="{disabled: noNext()||ngDisabled}" class="pagination-next disabled" style=""&gt;&lt;a href="" ng-click="selectPage(page + 1, $event)" ng-disabled="noNext()||ngDisabled" uib-tabindex-toggle="" disabled="disabled" tabindex="-1"&gt;Next&lt;/a&gt;&lt;/li&gt;
      &lt;a href="" ng-click="selectPage(page + 1, $event)" ng-disabled="noNext()||ngDisabled" uib-tabindex-toggle="" disabled="disabled" tabindex="-1"&gt;Next&lt;/a&gt;
  &lt;/li&gt;
  </code></pre>