title: Creating a page count down in Python Selenium
body: <p>I have a simple script that navigates to a series of pages.</p>
  
  <p>My question is, how do I create a page counter so I know where the job is at for this?</p>
  
  <p>Ideally it would read:</p>
  
  <pre><code>Page 5
  Page 4 #For each loop
  </code></pre>
  
  <p>The following tends to work, though I am having issues with the following:</p>
  
  <pre><code>elements = [x.get_text() for x in
          wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'(//div[div/div/text()="Main Lists"]//div[starts-with(@class, "sm-CouponLink_Label") and normalize-space()]')))]
  </code></pre>
  
  <p>Related error:</p>
  
  <pre><code> line 36, in &lt;module&gt;
          wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'(//div[div/div/text()="Main Lists"]//div[starts-with(@class, "sm-CouponLink_Label") and normalize-space()]')))]
        File "C:\Users\Django\AppData\Local\Continuum\miniconda3\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
          raise TimeoutException(message, screen, stacktrace)
      selenium.common.exceptions.TimeoutException: Message: 
  </code></pre>
  
  <p>Full code:</p>
  
  <pre><code>import collections
  from random import shuffle
  
  from selenium import webdriver
  from selenium.common.exceptions import TimeoutException
  from selenium.webdriver.common.by import By
  from selenium.webdriver.support import expected_conditions as EC
  from selenium.webdriver.support.ui import WebDriverWait as wait
  
  driver = webdriver.Chrome()
  driver.set_window_size(1024, 600)
  driver.maximize_window()
  
  
  driver.get('https://www.bet365.com.au/#/AS/B1/')
  driver.get('https://www.bet365.com.au/#/AS/B1/')
  
  
  
  def page_counter():
      for x in range(1000):
          yield x
  
  
  clickMe = wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'(//div[div/div/text()="Main Lists"]//div[starts-with(@class, "sm-CouponLink_Label") and normalize-space()])')))
  options = driver.find_elements_by_xpath('//div[div/div/text()="Main Lists"]//div[starts-with(@class, "sm-CouponLink_Label") and normalize-space()]')
  
  indexes = [index for index in range(len(options))]
  shuffle(indexes)
  for index in indexes:
  
  
      count = page_counter()
      driver.get('https://www.bet365.com.au/#/AS/B1/')
      elements = [x.get_text("*") for x in
              wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'(//div[div/div/text()="Main Lists"]//div[starts-with(@class, "sm-CouponLink_Label") and normalize-space()]')))]
  
  
         #elements = [x.get_attribute("href") for x in
         # driver.find_elements_by_xpath('//div[div/div/text()="Main Lists"]//div[starts-with(@class, "sm-CouponLink_Label") and normalize-space()]')))]
  
      clickMe.click()
      shuffle(elements)
  
      links = dict((next(count) + 1, e) for e in elements)
  
  desc_links = collections.OrderedDict(sorted(links.items(), reverse=True))
  for key, value in desc_links.items():
      try:
          driver.get(value)
          print('Page ' + str(key))
      except TimeoutException as ex:
          pass
  </code></pre>
  
  <p>Alternative:</p>
  
  <pre><code>import collections
  import time
  
  from selenium import webdriver
  
  driver = webdriver.Chrome()
  driver.set_window_size(1024, 600)
  driver.maximize_window()
  
  driver.get('https://www.bet365.com.au/#/AS/B1/')
  
  driver.find_element_by_id('TopPromotionBetNow').click()
  
  
  def page_counter():
      for x in range(1000):
          yield x
  
  
  count = page_counter()
  time.sleep(10)
  classifications = driver.find_elements_by_class_name('wn-Classification')
  for classification in classifications:
      if classification.text == 'Soccer':
          classification.click()
          break
  
  time.sleep(10)
  markets = driver.find_elements_by_class_name('sm-Market')
  for market in markets:
      group_name = market.find_element_by_class_name('sm-Market_GroupName')
      if group_name.text == 'Main Lists':
          coupon_lables = [x for x in market.find_elements_by_class_name('sm-CouponLink_Label')]
      break
  
  coupon_lables = [x.text for x in market.find_elements_by_class_name('sm-CouponLink_Label')]
  
  links = dict((next(count) + 1, e) for e in coupon_lables)
  
  desc_links = collections.OrderedDict(sorted(links.items(), reverse=True))
  for key, value in desc_links.items():
  
      for label in coupon_lables:
          print('Page ' + str(key))
          print('executing:' + label)
          time.sleep(5)
          driver.find_element_by_xpath(f'//div[contains(text(), "' + label + '")]').click()
          time.sleep(5)
          driver.find_element_by_class_name('cl-BreadcrumbTrail_BackButton').click()
  </code></pre>
  
  <p>My output:</p>
  
  <pre><code>Page 12
  executing:UK Saturday's Matches
  Page 12
  executing:Spanish Saturday's Matches
  Page 12
  executing:Italian Saturday's Matches
  Page 12
  executing:International Saturday's Matches
  Page 12
  executing:Europe Saturday's Matches
  </code></pre>
  
  <p>Desired:</p>
  
  <pre><code>Page 12
  Page 11
  Page 10
  </code></pre>
  
  <p>Any idea how I can fix this</p>