How can I get a intermediate URL from a redirect chain from Selenium using Python?
event-handling, python, redirect, selenium, selenium-webdriver
Solution
Answer my own question.
If the redirect chain is very long, consider to try the methods @alecxe and @Krishnan provided. But in this specific case, I've found a much easier workaround:
When the page finally landed c.com, use `driver.execute_script('return window.document.referrer')` to get the intermediate URL
Problem
I'm using Selenium with Python API and Firefox to do some automatic stuff, and here's my problem: - Click a link on original page, let's say on page a.com - I'm redirected to b.com/some/path?arg=value - And immediately I'm redirected again to the final address c.com So is there a way to get the intermediate redirect URL b.com/some/path?arg=value with Selenium Python API? I tried `driver.current_url` but when the browser is on b.com, seems the browser is still under loading and the result returned only if the final address c.com is loaded. Another question is that is there a way to add some event handlers to Selenium for like URL-change? Phantomjs has the capacity but I'm not sure for Selenium.