Skip to content

Instantly share code, notes, and snippets.

@SarahElson
Created June 29, 2022 17:38
Show Gist options
  • Save SarahElson/617b78541ac89022ba994ea7559643bc to your computer and use it in GitHub Desktop.
Save SarahElson/617b78541ac89022ba994ea7559643bc to your computer and use it in GitHub Desktop.
How To Get Current URL In Selenium Python
import pytest
from pages.selenium_playground import SeleniumPlaygroundPage
def test_selenium_playground(browser):
playground_page = SeleniumPlaygroundPage(browser)
playground_page.load()
playground_page.simple_form()
# Get the current url of the page in a variable
get_url = browser.current_url
title = browser.title
# Display the url in the console
print("The current url is: "+str(get_url))
# Save the url in a urls.txt file
with open('urls.txt', 'a') as f:
f.write(title + " : "+ get_url)
f.write('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment