Created
June 29, 2022 17:38
-
-
Save SarahElson/617b78541ac89022ba994ea7559643bc to your computer and use it in GitHub Desktop.
How To Get Current URL In Selenium Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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