title: Selenium: stop loop once element is class is disabled
body: <p>Currently trying to loop through all the pages on this website:</p>
  <ul>
  <li><a href="https://ephisahs.microsoftcrmportals.com/disclaimer/restaurantinspections/south-facilities/" rel="nofollow noreferrer">https://ephisahs.microsoftcrmportals.com/disclaimer/restaurantinspections/south-facilities/</a></li>
  </ul>
  <p>When it reaches page 53 (end of the page), it continues to loop even though there are no more pages. How can I make the loop stop? I notice that the element class =&quot;disabled&quot; appears.</p>
  <p><a href="https://i.stack.imgur.com/7jqKR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7jqKR.png" alt="enter image description here" /></a></p>
  <p>Here is my code so far:</p>
  <pre><code>driver = webdriver.Chrome(ChromeDriverManager().install())
  driver.implicitly_wait(10)
  driver.get('https://ephisahs.microsoftcrmportals.com/disclaimer/restaurantinspections/south-facilities/')
  
  dfs = []
  page_counter = 0
  while True:
  
      wait = WebDriverWait(driver, 30)
      wait.until(EC.visibility_of_all_elements_located((By.XPATH, &quot;//tr[@data-name]&quot;)))
      cards = driver.find_elements_by_xpath(&quot;//tr[@data-name]&quot;)
      facilities = []
      for card in cards:
          name = card.find_element_by_xpath(&quot;.//td[@data-th='Unit Name']&quot;).text
          street1 = card.find_element_by_xpath(&quot;.//td[@data-th='Site Street 1']&quot;).text
          street2 = card.find_element_by_xpath(&quot;.//td[@data-th='Site Street 2']&quot;).text
          site_city = card.find_element_by_xpath(&quot;.//td[@data-th='Site City']&quot;).text
          site_prov = card.find_element_by_xpath(&quot;.//td[@data-th='Site Province/State']&quot;).text
          site_code = card.find_element_by_xpath(&quot;.//td[@data-th='Site Postal Code/Zip Code']&quot;).text
          site_fac = card.find_element_by_xpath(&quot;.//td[@data-th='Facility Category']&quot;).text
          site_inspection = card.find_element_by_xpath(&quot;.//td[@data-th='Inspections Completed']&quot;).text
          ref_link = card.find_element_by_xpath(&quot;.//td//a&quot;).get_attribute(&quot;href&quot;)
          
          facilities.append([name, street1, street2, site_city,site_prov,site_code,site_fac,site_inspection,ref_link])
  
      df = pd.DataFrame(facilities)    
      dfs.append(df)
      
      print(page_counter)
      page_counter+=1
      try:
          wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,&quot;a[aria-label='Next page']&quot;))).click()
      
      except:
          break
          
  driver.close()
  driver.quit()
  </code></pre>