pythonplaywrightplaywright-python

How to get playwright page url


I am trying to get the current page url in python and playwright. I have tried:

from playwright.sync_api import sync_playwright
with sync_playwright() as p:
   browser = p.chromium.launch(headless=False, channel='chrome')
   context = browser.new_context(accept_downloads=True)
   page = context.new_page()
   page.goto("https://google.com")
   page.wait_for_timeout(5000)
   pageurl = page.url()

last line gives error: Exception has occurred: TypeError 'str' object is not callable What am I doing wrong?


Solution

  • That's because url is not a function. You can just simply do:

    pageurl = page.url
    print(pageurl)