How can I get a intermediate URL from a redirect chain from Selenium using Python?

1,392 views
Skip to first unread message

zhz shi

unread,
Feb 23, 2016, 10:28:16 PM2/23/16
to Selenium Users
Hi all,


I'm using Selenium with Python API and Firefox to do some automatic stuff, and here's my problem:

  1. Submit a form on original page, let's say on address a.com
  2. I'm redirected to b.com/some/path?arg=value
  3. 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 it's still loading and the result only returned once the final address c.com is finished loading.

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.

Can anybody help me on this? Thanks in advance :-)

Krishnan Mahadevan

unread,
Feb 23, 2016, 10:42:24 PM2/23/16
to Selenium Users
You can try getting this information by plugging in a proxy server such as BrowserMob Proxy [ https://github.com/lightbody/browsermob-proxy ]

AFAIK there is no way to hook in event handlers into Selenium because, the browser doesn't let you do that and Selenium WebDriver tries mimicking a real user's experience when interacting with a web page using a browser.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/08e22909-2f90-463e-b9ca-9fe5bb8c79d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

zhz shi

unread,
Feb 24, 2016, 1:38:04 AM2/24/16
to Selenium Users
Thanks Krishnan, I'll have a look at it.

Krishnan Mahadevan

unread,
Feb 24, 2016, 1:39:51 AM2/24/16
to Selenium Users
I also added a few more details to your query on StackOverFlow. Please take a look

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Reply all
Reply to author
Forward
0 new messages