Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

docs(python): fix outdated waitForResponse example (#5685)

Max Schmitt2a6bb5042570
diff --git a/docs/src/api/class-page.md b/docs/src/api/class-page.md
index 58d0e2d198..3d0e11f77e 100644
--- a/docs/src/api/class-page.md
+++ b/docs/src/api/class-page.md
@@ -2950,15 +2950,29 @@ return finalResponse.ok();
```
```python async
-first_response = await page.wait_for_response("https://example.com/resource")
-final_response = await page.wait_for_response(lambda response: response.url == "https://example.com" and response.status === 200)
-return final_response.ok
+async with page.expect_response("https://example.com/resource") as response_info:
+ await page.click("input")
+response = response_info.value
+return response.ok
+
+# or with a lambda
+async with page.expect_response(lambda response: response.url == "https://example.com" and response.status === 200) as response_info:
+ await page.click("input")
+response = response_info.value
+return response.ok
```
```python sync
-first_response = page.wait_for_response("https://example.com/resource")
-final_response = page.wait_for_response(lambda response: response.url == "https://example.com" and response.status === 200)
-return final_response.ok
+with page.expect_response("https://example.com/resource") as response_info:
+ page.click("input")
+response = response_info.value
+return response.ok
+
+# or with a lambda
+with page.expect_response(lambda response: response.url == "https://example.com" and response.status === 200) as response_info:
+ page.click("input")
+response = response_info.value
+return response.ok
```
### param: Page.waitForResponse.urlOrPredicate