Hi, I am new to playwright. When I enter my company internal website address there is a new window(Microsoft authentication page) that automatically pops up and once I enter the username and pwd the pop up/login window automatically closes and the content on my company website starts to load. I am trying to repeat this in playwright and when I navigate to the page using page.goto, I can see a new authentication window opening up. But, I am not able to switch to that authentication window to fill in my username and pwd. Can anyone help me how to handle switching to authentication page and switching back to actual website once authentication is done? I tried using page.on("page", handle_page) from the playwright docs but I never see anything getting printed out. Any help is appreciated since I am stuck on this for a while. Following is my piece of code.
from playwright.sync_api import Page, expect, sync_playwright,Playwright import os
def incercept_request(request): print('requested URL: ', request.url)
def incercept_response(response): print(f'response URL:{response.url}, Status:{response.status}')
def handle_page(page): page.wait_for_load_state() print('new page title:{}'.format(page.title()))
def run(playwright: Playwright) -> None: app_data_path = os.getenv("LOCALAPPDATA") user_data_path = os.path.join(app_data_path,'Chromium\UserData\Default') browser = playwright.chromium.launch_persistent_context(user_data_path,channel='chrome',headless=False,timeout=0)
page1 = browser.new_page()
page1.goto("Internal Website Link Here")
page1.on("page", handle_page)
with sync_playwright() as playwright: run(playwright)
This thread is trying to answer question "How to handle switching to an authentication page and switching back to the main website after authentication in Playwright?"
Does this answer your question? https://ray.run/questions/how-do-i-manage-authentication-popups-in-playwright
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].