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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] make scroll into view optional for page.click() #5716

Closed
Nilsty opened this issue Mar 4, 2021 · 6 comments
Closed

[Feature] make scroll into view optional for page.click() #5716

Nilsty opened this issue Mar 4, 2021 · 6 comments

Comments

@Nilsty
Copy link

Nilsty commented Mar 4, 2021

Problem statement:
I have a dropdown menu where the bottom part is cut off. The elements which are cut off are still clickable as page.click() will scroll them into view. But I would like to make sure that all elements of the dropdown are fully visible without scrolling.

Proposed solution
My proposed solution would be to make the scrolling into view optional for page.click() as an option. E.g. scroll=false

Additional context
image

This issue seems somewhat related to #5700

@pavelfeldman
Copy link
Member

To make sure I understand, you would want to say

await page.click('text=Rename draft', { scroll: false });

It will click the center of the visible portion, so it'll work in this case. What signal would it give to you? Or are you worried about other elements that are not visible altogether? Or does your menu have overflow: auto? Trying to make sense of this!

@Nilsty
Copy link
Author

Nilsty commented Mar 5, 2021

Thanks for your question @pavelfeldman
There are more elements in this dropdown. This is how it looks when it's not cut off:
image
So, my idea would be to check if the last element in this dropdown is clickable without scrolling by doing something like this:

await page.click('(//li)[last()]', { scroll: false });

image

@pavelfeldman
Copy link
Member

It looks like you don't care whether user is able to click it for real, you just want to trigger it, is that right? In that case you can just

await page.dispatchEvent('(//li)[last()]', 'click')

that's just trigger it programmatically.

Playwright's way of clicking is 'tapping on the glass', i.e. as if user clicked it using pointer controller or finger tap. So if we don't scroll, we can't click...

@Nilsty
Copy link
Author

Nilsty commented Mar 9, 2021

await page.dispatchEvent('(//li)[last()]', 'click')
is still scrolling the element into view. It would be great to have a way to suppress that scrolling behavior.

@yury-s
Copy link
Member

yury-s commented Mar 10, 2021

Could it be that one of the the click handlers in the page performs scrolling? If you try the following snippet it will dispatch 'click' without scrolling (while page.click would scroll), something is different in your page:

  await page.goto('https://github.com/microsoft/playwright/issues/5716');
  await page.dispatchEvent('text=is still scrolling the element', 'click');

@aslushnikov
Copy link
Contributor

await page.dispatchEvent('(//li)[last()]', 'click') is still scrolling the element into view.

@Nilsty Similarly to Yury, I don't see this happening anywhere in our code as well. I'll close this for now since it does look like dispatchEvent solves the usecase here. If you believe that it doesn't, or if dispatchEvent somehow scrolls element for you - please re-submit with a repro steps so that we can debug locally!

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

No branches or pull requests

4 participants