Skip to content

[Feature Request]: Expect Page Load context manager #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 tasks done
dickermoshe opened this issue May 12, 2025 · 0 comments
Open
2 tasks done

[Feature Request]: Expect Page Load context manager #130

dickermoshe opened this issue May 12, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@dickermoshe
Copy link

dickermoshe commented May 12, 2025

Checklist before requesting

  • I have searched for similar feature requests and didn't find a duplicate.
  • I have checked the documentation to confirm this feature doesn't already exist.

Problem Statement

Many times a button click should trigger a page load and you need to wait for the new page to be loaded.
You can wait for this by waiting for a certain element to be visible on the next page, but many times this is not possible.

In my case it is because besides for some changed cookies, the next page is completely identical to the 1st page.

Proposed Solution

I would love to have an async context manager which only returns when a load event is fired.
This is how I'm using it in my code.

@asynccontextmanager
async def expect_page_load(self, timeout: int = 10):
    event = asyncio.Event()

    async def event_handler(_):
        event.set()

    if self.page_events_enabled is False:
        _before_page_events_enabled = False
        await self.enable_page_events()
    else:
        _before_page_events_enabled = True

    await self.on(
        PageEvents.PAGE_LOADED, event_handler, temporary=True
    )

    yield

    await asyncio.wait_for(event.wait(), timeout=timeout)

    if _before_page_events_enabled is False:
        await self.disable_page_events()

Usage would look like

async with page.expect_page_load():
    ... # Do something which  should trigger a reload

# Continues here upon reload, or throws if timed out

Alternatives Considered

No response

Additional Context

No response

Importance

Important

Contribution

Yes, I'd be willing to implement this feature

@dickermoshe dickermoshe added the enhancement New feature or request label May 12, 2025
@dickermoshe dickermoshe changed the title [Feature Request]: [Feature Request]: Expect Page Load context manager May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant