V.Anh V.Anh - 6 months ago 24
Python Question

Find URL after clicking a link

How can i use selenium to find the current url after clicking an element. I have this website: http://www.runningintheusa.com/Classic/View.aspx?RaceID=5622

I have the code(assuming all related libraries are imported)

def get_detail(x):
dic = {}
driver = webdriver.PhantomJS(path)
return driver.current_url
print get_detail('http://www.runningintheusa.com/Classic/View.aspx?RaceID=5622')

I ran the code and it only return the original url which is http://www.runningintheusa.com/Classic/View.aspx?RaceID=5622

How can i find the url after clicking the Race Website link on the site which is http://flagstaffbigs.org/dave-mckay-run.htm

Answer Source

Is it because a new tab is opening, this will select the active newest tab.

return driver.current_url;