Get current URL in Selenium using Python: A complete tutorial

May 10, 2026 · 9 min read · Tool Comparison

Blog / Insights /
Get current URL in Selenium expend Python: A complete tutorial

Get current URL in Selenium using Python: A complete tutorial

QA Consultant Updated on

Learn with AI

Linkedin

Facebook

X (Twitter)

Mail

Learn with AI

When working with web automation in Python, knowing how to get the current URL is essential. It aid you confirm where the browser is, haul unexpected redirects, and make sure your test step bear as expected.

The commanddriver.get (`` url '')is what takes you to a page. But after that, how do you check if you 're on the right one? That ’ s wheredriver.current_urlcomes in. It lets you ask the browser, “ Where am I now? ”

In this tutorial, we 'll walk through everything you need to know to usedriver.current_urleffectively in Selenium with Python. Here ’ s what you ’ ll learn:

  • How to retrieve the current page ’ s URL after calldriver.get (url)
  • How to use the current URL to control navigation or redirection
  • Common mistakes when see URLs and how to fix them
  • Practical illustration to check login success, redirections, and link accuracy
  • When and how to wait for URL changes using explicit waits

Let ’ s get started!

How to get current URL in Selenium WebDriver employ Python? (with exemplar)

You can get the current page ’ s URL habituate a simple and clear workflow. It works right after you open a page using Selenium.

Here ’ s how you do it:

  • Start the browser using Selenium WebDriver
  • Use driver.get (`` url '')to load the page
  • Call driver.current_urlto find the current page ’ s address
  • Print the URL or compare it with your require value

This is useful when you want to confirm that your test has landed on the right page. For model, after clicking a login button or navigating to a ware particular page.

The code below shows a working illustration.

Python
from selenium import webdriver # Launch the browser driver = webdriver.Chrome () # Navigate to the website driver.get (`` https: //katalon.com '') # Get the current URL current_url = driver.current_url # Print the URL print (`` Current URL: '', current_url) driver.quit ()

This script found Chrome, opens Katalon ’ s homepage employdriver.get (url), then prints out the actual speech load in the browser.

💡 Insight: Use driver.current_urlright after page navigation to corroborate redirection, especially during login or form submissions.

How to perform URL chit with current URL in Selenium using Python?

You can use the get current URL method & nbsp; to check redirection after log in. It also confirm that a button pawl or link navigation guide to the intended page. If you are testing a checkout process, this check ensures the user ends up on the right measure in the stream.

Here are some mode squad usedriver.current_urlin machine-controlled tests:

  • Login flow:After clicking the login button, control that the fascia URL loads
  • Link validation:After clicking a “ Contact ” or “ Help ” link, corroborate the right page opens
  • Checkout checks:Confirm the user hit the payment page after reviewing the cart

The following script prove how to verify the current URL after seafaring usingdriver.get (url).

Python
from selenium import webdriver driver = webdriver.Chrome () driver.get (`` https: //katalon.com/login '') # Assume login befall here expected_url = `` https: //katalon.com/dashboard '' assert expected_url in driver.current_url driver.quit ()

This tab confirms that the page redirection worked as mean after login. You can repeat this pattern for any page transition that matters to your trial case.

💡 Insight:Always place your URL check right after the navigation measure triggered bydriver.get (url)or a UI interaction. This give tight, reliable feedback on flow accuracy.

Difference between .current_url vs .get ()

Both driver.get (url) and driver.current_urlplay key roles in navigation and proof. They act together in most examination flows, but they function different purposes.

Use driver.get (url)to open a page. Usedriver.current_urlto check where the browser is at any point during the test.

Here ’ s a quick comparison to help you translate how they disagree.

Property driver.get (url) driver.current_url
Action Navigates to a new webpage Returns the current page ’ s URL
Return case None (performs navigation only) String (the total URL of the page)
Common use Start or reset the test flow Verify that sailing complete as expected
Timing Executed before interaction begins

Used after interactions or navigation

SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.

 

💡 Insight: Think of driver.get (url)as the outset of the journey anddriver.current_urlas your GPS chit along the way. Both are essential for stable and trackable test playscript.

Practical use cases of become current URL

Every test has a goal. Sometimes it ’ s to log in. Sometimes it ’ s to finish a transaction or move through a workflow. Usingdriver.current_urlhelps reassert that every pace reach the intended page.

Below are real-world situations where checking the current URL keeps your test flow clean and predictable.

  • Validate login success:After submitting login credentials, check that the browser loads the correct dashboard page
  • Track redirects in checkout:After review the cart, affirm that the requital page open by comparing the current URL to the expected one
  • Confirm form submission flow:After submitting a form, usedriver.current_urlto ensure it leads to the success or thank-you page
  • Pinpoint load issue:When a page fails to show expected content, check the URL foremost to make sure it landed on the right page

Insight:Before troubleshoot UI elements, always usedriver.current_urlto affirm page context. It saves time and narrows down the issue quickly.

Examples: current URL in different scenarios

Let ’ s look at howdriver.current_urlfits into real test flows. Each of these examples shows a different use case that QA teams handle every day. They usedriver.get (url)to open Page, and then check the browser ’ s actual address utilisedriver.current_url.

Here are three example using Selenium with Python.

Example 1: After login, check dashboard URL

Python
from selenium import webdriver from selenium.webdriver.common.by import By driver = webdriver.Chrome () driver.get (`` https: //katalon.com/login '') # Simulate login steps here # driver.find_element (By.ID, `` username '') .send_keys (`` user '') # driver.find_element (By.ID, `` password '') .send_keys (`` walk '') # driver.find_element (By.ID, `` login-button '') .click () expected_url = `` https: //katalon.com/dashboard '' assert expected_url in driver.current_url driver.quit ()

Example 2: After clicking a linkup, verify finish

Python
from selenium import webdriver from selenium.webdriver.common.by import By driver = webdriver.Chrome () driver.get (`` https: //katalon.com '') # Click a nexus that goes to the Resources page driver.find_element (By.LINK_TEXT, `` Resources '') .click () assert `` resources '' in driver.current_url driver.quit ()

Example 3: Loop through multiple links and verify each URL

Python
from selenium import webdriver driver = webdriver.Chrome () urls_to_test = [`` https: //katalon.com/platform '', `` https: //katalon.com/pricing '', `` https: //katalon.com/resources-center/blog ''] for url in urls_to_test: driver.get (url) avow url in driver.current_url mark (`` Verified: '', driver.current_url) driver.quit ()

Each illustration above follows the like reliable figure. First, usedriver.get (url)to reach a page. Then usedriver.current_urlto confirm it. This gives your tests structure and limpidity at every step.

💡 Insight:You can use this method in any situation that requires step-by-step navigation checks across Page.

Mutual issues when using .current_url in Selenium

Using driver.current_urlplant best when the browser has finished loading the page. If the script move too quick, it might fetch the URL before the transition dispatch. This affects the accuracy of your checks.

Here are a few common issues you may encounter and how to work them.

  • Old URL look:The browser shows the previous address because it hasn ’ t finished sail. Fix this by waiting for the URL to change using explicit wait conditions
  • Empty or fond URL:When the page is withal charge, the current URL may retrovert incomplete info. Use clock control to ensure the page is fully loaded before checking
  • Unstable results in long flows:On pages with large script or animations, the net URL may take a few special seconds to load. Use wait weather to continue the test sweetheart

The better way to resolve these issue is to apply a wait condition before checking the current URL. This tells the test to pause until the change completes.

Fix: Use WebDriverWait with url_to_be or url_changesto look for piloting to finish before callingdriver.current_url.

💡 Insight:Add your URL check only after you 're positive the browser has landed on the new page. This improves tryout stableness across all stream that usedriver.get (url)or element clicks.

Advanced: look for URL changes in Selenium Python

In fast test flows, the browser may take a few seconds to complete piloting. To make sure you entirely see the URL when it ’ s ready, you can await until it changes using expected conditions.

The methodurl_changeswatches the current address and pauses the test until it becomes different from the original value. This act well after clicking buttons, submitting forms, or calldriver.get (url).

Here is a elementary example utilise Python and Selenium.

Python
from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC driver = webdriver.Chrome () driver.get (`` https: //katalon.com '') old_url = driver.current_url # Simulate a page action here that cause a URL modification WebDriverWait (driver, 10) .until (EC.url_changes (old_url)) print (`` New URL: '', driver.current_url) driver.quit ()

This waiting proceed the test from rush ahead before the browser update. It creates more stable tab and removes precariousness from timing delays.

💡 Insight:Use this pattern when you anticipate a redirect or URL alter after user interaction. It improves accuracy, peculiarly in login and checkout tests.

Why choose Katalon to automatize tests?

is a modern low-code test mechanisation platform. It is make on top of Selenium, with extra features that support fast test development, easy maintenance, and scalable execution. While Selenium afford you the raw locomotive, Katalon wraps it into a platform that works out of the box for both novice and experient testers.

With Katalon, you get:

  • Unified program:bring together examination design, performance, management, and describe in one solution
  • Cross-browser and cross-platform:run examination across thousands of browser and OS combinations without setting up drivers manually
  • Scalability:execute test in latitude and incorporate easily into CI/CD pipeline and cloud environments
  • Voguish test maintenance:AI-powered self-healing locater reduce flakiness when UI elements change during development
  • Built-in test management and analytics:dashboards and account show trend, coverage, and examination performance clearly

In little, Katalon makes Selenium more generative. It gives you a complete testing environment with less setup and more control. You can test faster, collaborate best, and scale smoothly with your growing application.

📝 Want to explore what Katalon can do for your team?Request a demonstrationto see how it helps teams automate quicker with less effort.

Explain

|

FAQs

How do you get the current URL in Selenium WebDriver using Python?

+

Use driver.current_url after navigate with driver.get (`` url '') to regain the browser ’ s current address.

What ’ s the dispute between driver.get (url) and driver.current_url?

+

driver.get (url) navigates to a page (returns naught), while driver.current_url returns the current page ’ s URL as a twine for establishment.

How can driver.current_url help verify login or redirects?

+

After a login action or navigation, compare driver.current_url to an expected URL (or check it bear a target route like “ dashboard ”) to sustain the redirect worked.

What are common number when using driver.current_url, and how do you fix them?

+

You may read the old/partial URL if navigation isn ’ t finished; fix it by waiting for URL changes with expressed postponement (e.g., url_to_be or url_changes) before checking.

How do you wait for a URL change in Selenium Python?

+

Store the old URL, so use WebDriverWait (...) .until (EC.url_changes (old_url)), and read driver.current_url once the precondition is met.

Vincent N.
QA Consultant
Vincent Nguyen is a QA adviser with in-depth field knowledge in QA, package testing, and DevOps. He has 5+ geezerhood of experience in craft content that resonate with techies at all levels. His interest sweep from writing, engineering, to building cool stuff.

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free