What is the Python code to get the current URL using Selenium WebDriver?
Hi Priyanka
Hope this answer finds you well! I’m thrilled to share an enchanting snippet of code that unveils the wondrous power of the current_url attribute in Selenium. Brace yourself for a journey into the digital realm!
Using current_url attribute: Use the current_url attribute of the WebDriver object to retrieve the current URL.
from selenium import webdriver
driver = webdriver.Chrome() driver.get(‘https://www.example.com’)
current_url = driver.current_url print(“Current URL:”, current_url)
driver.quit()