Verify URL in Selenium Python

Profile picture for user arilio666

To verify a URL in Selenium using Python, you can use the current_url property of the WebDriver object. Here's an example:

from selenium import webdriver
from import ChromeDriverManager
from import By
from import Service

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))


current_url = driver.current_url
if current_url == '':
   print('URL verified successfully')
   print('URL verification failed')
  • In this example, we first create a new instance of the Chrome driver using webdriver.Chrome()
  • We then navigate to a URL using driver.get(), and retrieve the current URL using driver.current_url
  • We can then compare the current URL to the expected URL using an if statement