Skip to content

[Question] Does page.click automatically page.waitForNavigation? #2078

@aesyondu

Description

@aesyondu

In the release notes of 0.14.0, under Breaking API Changes, there is a phrase that says:

Actions that automatically wait for the navigation like page.click(selector[, options]) ...etc.

I need help understanding what that means. In the current documentation for page.waitForNavigation, the page.waitForNavigation and page.click promise combo is shown as an example for properly handling indirect navigation:

const [response] = await Promise.all([
  page.waitForNavigation(), // The promise resolves after navigation has finished
  page.click('a.my-link'), // Clicking the link will indirectly cause a navigation
]);
  1. What is a direct navigation? What is an indirect navigation?
    From the example above, I can infer that clicking an <a href="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/"> link is an indirect navigation.
  2. Is submitting an html form direct or indirect navigation?
    Navigation via javascript/xhr/ajax is most likely an indirect navigation
  3. Is it safe to assume that page.click only waits for direct navigation?
  4. What types of navigation does page.click wait for automatically, as mentioned in the release notes?

EDIT: Also from the page.click documentation:

noWaitAfter - Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. Defaults to false.

  1. If clicking an <a href> link is an indirect navigation, meaning the noWaitAfter doesn't apply, meaning page.waitForNavigation is needed, which navigations does the docs pertain to?

The reason I ask is, in the previous playwright version, 0.13.0, my tests which included the following lines, worked fine:

// log in by submitting an html form
await page.click('input[value="Log in"]');
await saveScreenshot(page, fileName);

However, in the current version (0.16.0), it is now raising an error:

Cannot take a screenshot while page is navigating

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions