Fix Python – How do I get current URL in Selenium Webdriver 2 Python?

Question

Asked By – user2276896

I’m trying to get the current url after a series of navigations in Selenium. I know there’s a command called getLocation for ruby, but I can’t find the syntax for Python.

Now we will see solution for issue: How do I get current URL in Selenium Webdriver 2 Python?


Answer

Use current_url element for Python 2:

print browser.current_url

For Python 3 and later versions of selenium:

print(driver.current_url)

This question is answered By – 4d4c

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0