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 webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service

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

driver.maximize_window()
driver.get('https://www.programsbuzz.com')

current_url = driver.current_url
print(current_url)
if current_url == 'https://www.programsbuzz.com/':
   print('URL verified successfully')
else:
   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