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

Question:

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.

Asked By: user2276896

||

Answers:

Use current_url element for Python 2:

print browser.current_url

For Python 3 and later versions of selenium:

print(driver.current_url)
Answered By: 4d4c

Selenium2Library has get_location():

import Selenium2Library
s = Selenium2Library.Selenium2Library()
url = s.get_location()
Answered By: Milanka

According to this documentation (a place full of goodies:)):

driver.current_url

or, see official documentation:
https://www.selenium.dev/documentation/en/webdriver/browser_manipulation/#get-current-url

Answered By: pbaranski

Another way to do it would be to inspect the url bar in chrome to find the id of the element, have your WebDriver click that element, and then send the keys you use to copy and paste using the keys common function from selenium, and then printing it out or storing it as a variable, etc.

Answered By: LiamººT