Skip to content

Instantly share code, notes, and snippets.

@SarahElson
Created June 29, 2022 17:33
Show Gist options
  • Save SarahElson/9ff8a9e0dc6051ad53390d74e5ecd411 to your computer and use it in GitHub Desktop.
Save SarahElson/9ff8a9e0dc6051ad53390d74e5ecd411 to your computer and use it in GitHub Desktop.
How To Get Current URL In Selenium Python
import pytest
from pages.ecommerce_playground import EcommercePlaygroundPage
keyword = "iPhone"
def test_ecommerce_playground(browser):
ecommerce_page = EcommercePlaygroundPage(browser)
ecommerce_page.load()
ecommerce_page.search(keyword)
get_url = browser.current_url
title = browser.title
print("The current url is: "+str(get_url))
assert "iPhone" in get_url
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