How to get current_url using Selenium in Python?
Last Updated :
06 Mar, 2020
While doing work with selenium many URL get opened and redirected in order to keeping track of URL current_url
method is used. The current_url
method is used to retrieve the URL of the webpage the user is currently accessing. It gives the URL of the current webpage loaded by the driver in selenium.
URL : URL is the abbreviation of Uniform Resource Locator and is defined as the global address of documents and other resources on the World Wide Web, for example, to visit GeeksforGeeks website, you’ll go to the URL https://www.geeksforgeeks.org/ .
Syntax :
driver.current_url
Argument :
It takes no argument.
Return value :
It return the URL in string format.
Code 1:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get(url)
get_url = driver.current_url
print (get_url)
|
Output :
https://www.geeksforgeeks.org/
Code 2:
from selenium import webdriver
driver = webdriver.Chrome()
get_url = driver.current_url
print (get_url)
driver.get(url)
get_url = driver.current_url
print (get_url)
|
Output :
data:,
https://www.geeksforgeeks.org/
Note: Here “data:, ” is printed because at that time no webpage is opened.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...