1

The current code takes me to the correct url, but ends up just printing the url I was at before.

for i in range(25):
        driver.find_element(By.XPATH, f'//*[@id="listing_{i}"]').click()
        print(driver.current_url)

I want to get the new current_url after performing the click() request

stevieg613
  • 11
  • 2
  • Add some wait before the print. Or you can do some waits like so https://stackoverflow.com/questions/42069503/python-selenium-wait-until-next-page-has-loaded-after-form-submit – Arundeep Chohan Nov 20 '21 at 00:22

1 Answers1

0

You can look into this question here for more help as your question is the same. The problem here is that you have switched to a new tab and the WebDriver no longer has context. It thinks you're still in the first tab. In order to fix this you need to switch your WebDriver to the most recently opened tab using this call: (Put this after the click() and before the print())

driver.switch_to.window(driver.window_handles[-1]);