Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check response in Playwright [closed]

I have I question about Playwright. When I make a request to a website with "page.goto("example_url.com")" Using page.on("response", lambda res: print(res.status)) It returns to me more than one response. My question is how do I deal with this kind of situation to determine if the page has responded to me successfully.

like image 365
Gentrit Hoxha Avatar asked Oct 24 '25 04:10

Gentrit Hoxha


1 Answers

page.goto returns the Response of the page where its navigating to. So you can do something like that:

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()

    response = page.goto("http://whatsmyuseragent.org/")
    assert response.ok

    browser.close()
like image 130
Max Schmitt Avatar answered Oct 25 '25 16:10

Max Schmitt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!