docs: do not recommend waitForLoadState (#30483)

Instead, just perform an action and auto-waiting will handle it.

Closes #30236.
This commit is contained in:
Dmitry Gozman 2024-04-23 09:22:58 -07:00 committed by GitHub
parent c80b851422
commit 02c0706896
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 34 additions and 11 deletions

View file

@ -1970,6 +1970,10 @@ Waits for the required load state to be reached.
This returns when the frame reaches a required load state, `load` by default. The navigation must have been committed This returns when the frame reaches a required load state, `load` by default. The navigation must have been committed
when this method is called. If current document has already reached the required state, resolves immediately. when this method is called. If current document has already reached the required state, resolves immediately.
:::note
Most of the time, this method is not needed because Playwright [auto-waits before every action](../actionability.md).
:::
**Usage** **Usage**
```js ```js

View file

@ -4465,6 +4465,10 @@ Returns when the required load state has been reached.
This resolves when the page reaches a required load state, `load` by default. The navigation must have been committed This resolves when the page reaches a required load state, `load` by default. The navigation must have been committed
when this method is called. If current document has already reached the required state, resolves immediately. when this method is called. If current document has already reached the required state, resolves immediately.
:::note
Most of the time, this method is not needed because Playwright [auto-waits before every action](../actionability.md).
:::
**Usage** **Usage**
```js ```js

View file

@ -143,7 +143,8 @@ handle new pages opened by `target="_blank"` links.
const pagePromise = context.waitForEvent('page'); const pagePromise = context.waitForEvent('page');
await page.getByText('open new tab').click(); await page.getByText('open new tab').click();
const newPage = await pagePromise; const newPage = await pagePromise;
await newPage.waitForLoadState(); // Interact with the new page normally.
await newPage.getByRole('button').click();
console.log(await newPage.title()); console.log(await newPage.title());
``` ```
@ -152,7 +153,8 @@ console.log(await newPage.title());
Page newPage = context.waitForPage(() -> { Page newPage = context.waitForPage(() -> {
page.getByText("open new tab").click(); // Opens a new tab page.getByText("open new tab").click(); // Opens a new tab
}); });
newPage.waitForLoadState(); // Interact with the new page normally
newPage.getByRole(AriaRole.BUTTON).click();
System.out.println(newPage.title()); System.out.println(newPage.title());
``` ```
@ -162,7 +164,8 @@ async with context.expect_page() as new_page_info:
await page.get_by_text("open new tab").click() # Opens a new tab await page.get_by_text("open new tab").click() # Opens a new tab
new_page = await new_page_info.value new_page = await new_page_info.value
await new_page.wait_for_load_state() # Interact with the new page normally
await new_page.get_by_role("button").click()
print(await new_page.title()) print(await new_page.title())
``` ```
@ -172,7 +175,8 @@ with context.expect_page() as new_page_info:
page.get_by_text("open new tab").click() # Opens a new tab page.get_by_text("open new tab").click() # Opens a new tab
new_page = new_page_info.value new_page = new_page_info.value
new_page.wait_for_load_state() # Interact with the new page normally
new_page.get_by_role("button").click()
print(new_page.title()) print(new_page.title())
``` ```
@ -182,7 +186,8 @@ var newPage = await context.RunAndWaitForPageAsync(async () =>
{ {
await page.GetByText("open new tab").ClickAsync(); await page.GetByText("open new tab").ClickAsync();
}); });
await newPage.WaitForLoadStateAsync(); // Interact with the new page normally
await newPage.GetByRole(AriaRole.Button).ClickAsync();
Console.WriteLine(await newPage.TitleAsync()); Console.WriteLine(await newPage.TitleAsync());
``` ```
@ -242,8 +247,8 @@ This event is emitted in addition to the `browserContext.on('page')` event, but
const popupPromise = page.waitForEvent('popup'); const popupPromise = page.waitForEvent('popup');
await page.getByText('open the popup').click(); await page.getByText('open the popup').click();
const popup = await popupPromise; const popup = await popupPromise;
// Wait for the popup to load. // Interact with the new popup normally.
await popup.waitForLoadState(); await popup.getByRole('button').click();
console.log(await popup.title()); console.log(await popup.title());
``` ```
@ -252,7 +257,8 @@ console.log(await popup.title());
Page popup = page.waitForPopup(() -> { Page popup = page.waitForPopup(() -> {
page.getByText("open the popup").click(); page.getByText("open the popup").click();
}); });
popup.waitForLoadState(); // Interact with the popup normally
popup.getByRole(AriaRole.BUTTON).click();
System.out.println(popup.title()); System.out.println(popup.title());
``` ```
@ -262,7 +268,8 @@ async with page.expect_popup() as popup_info:
await page.get_by_text("open the popup").click() await page.get_by_text("open the popup").click()
popup = await popup_info.value popup = await popup_info.value
await popup.wait_for_load_state() # Interact with the popup normally
await popup.get_by_role("button").click()
print(await popup.title()) print(await popup.title())
``` ```
@ -272,7 +279,8 @@ with page.expect_popup() as popup_info:
page.get_by_text("open the popup").click() page.get_by_text("open the popup").click()
popup = popup_info.value popup = popup_info.value
popup.wait_for_load_state() # Interact with the popup normally
popup.get_by_role("button").click()
print(popup.title()) print(popup.title())
``` ```
@ -282,7 +290,8 @@ var popup = await page.RunAndWaitForPopupAsync(async () =>
{ {
await page.GetByText("open the popup").ClickAsync(); await page.GetByText("open the popup").ClickAsync();
}); });
await popup.WaitForLoadStateAsync(); // Interact with the popup normally
await popup.GetByRole(AriaRole.Button).ClickAsync();
Console.WriteLine(await popup.TitleAsync()); Console.WriteLine(await popup.TitleAsync());
``` ```

View file

@ -4601,6 +4601,9 @@ export interface Page {
* committed when this method is called. If current document has already reached the required state, resolves * committed when this method is called. If current document has already reached the required state, resolves
* immediately. * immediately.
* *
* **NOTE** Most of the time, this method is not needed because Playwright
* [auto-waits before every action](https://playwright.dev/docs/actionability).
*
* **Usage** * **Usage**
* *
* ```js * ```js
@ -7399,6 +7402,9 @@ export interface Frame {
* committed when this method is called. If current document has already reached the required state, resolves * committed when this method is called. If current document has already reached the required state, resolves
* immediately. * immediately.
* *
* **NOTE** Most of the time, this method is not needed because Playwright
* [auto-waits before every action](https://playwright.dev/docs/actionability).
*
* **Usage** * **Usage**
* *
* ```js * ```js