To get the current URL in Python using Selenium, you can use the current_url
property of the WebDriver instance. Here’s how you can do it:
- Selenium Features
- Selenium Installation
- Selenium Locators
- XPath Fundamentals
- CSS Selectors Methods
- Different Browsers Execution
- find_element & find_elements
- Check Enabled Status
- Check Displayed Status
- Check Selected Status
- Selenium Waits
- Send_keys Method
- Click Method
- Get Text
- Get Attribute Value
- Get Current URL
- Forward, Back, Refresh
- Take Screenshot
- Handle Browser Tabs
- Handle iframe
- Mouse Hover
- Context-Click
- Drag & Drop
- Handle Alerts
- Handle Dropdown
- Execute Javascript
- Scroll To element
- Headless Mode Execution
- Chrome Options
- Keyboard Action
from selenium import webdriver
# Example using Chrome WebDriver
driver = webdriver.Chrome()
# Navigate to a website
driver.get("https://sqatools.in/")
# Get the current URL
current_url = driver.current_url
print("Current URL:", current_url)
# Close the browser
driver.quit()
This will print the current URL of the page that the WebDriver is on.