title: Updating driver url in a while loop - Selenium
body: <p>I have a small function that needs to click on a page, execute the function get_data - this works, click on the next page, perform get_data click the button move to the next page check that the button &quot;next page&quot; exists and repeat this process.</p>
  <p>So far all is good, but I just can get to update the driver url.</p>
  <pre><code>PATH = '/Applications/chromedriver'
  driver = webdriver.Chrome(PATH)
  
  def moving_pages():
      driver.get('https://link-page-1')
      while driver.find_element_by_class_name('next-page-btn'):
          button = driver.find_element_by_class_name('next-page-btn')
          button.click()
          time.sleep(4)
          get_data(driver.current_url)
          driver = driver.current_url
  </code></pre>
  <p>If I execute this I cannot update the driver because it is out of the scope. If I put the driver inside the while loop, the while loop will be False and will not execute.</p>
  <p>What is a work around to get the next page, update the driver, check that the button &quot;next-page-btn&quot; is present execute get_data(current_page) and move on to the next.</p>