Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Proper support for scrolling to the bottom of a page #30643

Closed
SamStephens opened this issue May 3, 2024 · 7 comments 路 Fixed by #30719
Closed

[Feature]: Proper support for scrolling to the bottom of a page #30643

SamStephens opened this issue May 3, 2024 · 7 comments 路 Fixed by #30719

Comments

@SamStephens
Copy link

馃殌 Feature Request

I'd like a simple method to allow me to scroll my browser page to the bottom. Something like

page.scroll_to_bottom()

Or maybe

page.scroll_to('bottom')

Where the possible answers are top and bottom.

Example

No response

Motivation

The motivation here is that scrolling to the bottom of a page is a common way to trigger infinite scrolling pages to load more content.

It's easy to search and find people working around the lack of this feature via Javascript. In fact, a Playwright developer suggests using Javascript in microsoft/playwright-python#683

However, I'd argue that infinite scrolling pages are common enough that this is a worthwhile feature to add to Playwright.

@SamStephens
Copy link
Author

This feature is also discussed in #1115 - however the issue was closed because mouse wheel interaction was implemented, but that doesn't solve the infinite scroll scenario.

Should this feature request be raised in https://github.com/microsoft/playwright rather than the Python specific repository?

@mxschmitt mxschmitt transferred this issue from microsoft/playwright-python May 3, 2024
@dgozman
Copy link
Contributor

dgozman commented May 3, 2024

@SamStephens This feature is not that straightforward. It's impossible to scroll to the bottom of an "infinite list" pattern. On many pages, instead of scrolling the document, you have to scroll some particular scrollable container inside. On other pages, you have to scroll an iframe instead. There are probably many more edge cases.

Given the limitations, we recommend:

  • Either evaluate("window.scrollBy(0, 100000)" if you know that scrolling the document is sufficient.
  • Or call locator.scroll_into_view_if_needed() with a locator somewhere at the bottom of the page. Most likely, that's actually what you need - to scroll up to some point.

Let me know whether the above methods work for you.

@SamStephens
Copy link
Author

I'm currently using evaluate("window.scrollBy(0, 100000)"), and that's the method I see most people using online.

I guess my thinking is why not wrap up evaluate("window.scrollBy(0, 100000)") in a method with a semantically meaningful name, if it's something a number of users have used, something with enough utility you and others recommend it to people.

@dgozman
Copy link
Contributor

dgozman commented May 8, 2024

I guess my thinking is why not wrap up evaluate("window.scrollBy(0, 100000)") in a method with a semantically meaningful name, if it's something a number of users have used, something with enough utility you and others recommend it to people.

Introducing an API requires a certain quality of the implementation. Due to the limitations I listed, we are not confident that we can implement such an API in a robust manner, unless it's called page.scrollDocumentScrollingElementToTheBottomMayBeFlaky() or similar. I'd really recommend scrolling some kind of a footer into view instead.

@SamStephens
Copy link
Author

@dgozman that's fair. I wonder if it's worth putting a little something in the documentation about scrolling practices, to pre-empt people with similar questions and problems to me. If not, I'm happy to close this issue; thanks for your explanations.

@SamStephens
Copy link
Author

Thanks for doing that @dgozman, I'm guessing you don't want to explicitly document evaluate("window.scrollBy(0, 100000)").

@dgozman
Copy link
Contributor

dgozman commented May 9, 2024

Thanks for doing that @dgozman, I'm guessing you don't want to explicitly document evaluate("window.scrollBy(0, 100000)").

Yep, we think that other methods are better and easier to explain.

thebigbrain pushed a commit to thebigbrain/playwright that referenced this issue May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants