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

mouse_to after a scroll_by #29

Open
psychaos9999 opened this issue Sep 9, 2022 · 3 comments
Open

mouse_to after a scroll_by #29

psychaos9999 opened this issue Sep 9, 2022 · 3 comments

Comments

@psychaos9999
Copy link

Hi,
the mouse position change in relation to viewport after a scroll.
I think the mouse movement after a scroll should start from the same point in relation to the viewport thatit has before the scroll.

Am I missing something?

Thank you in advence

@droefs
Copy link
Owner

droefs commented Sep 11, 2022

Hi, thank you for your question.

I am not sure whether I understand your question correctly. scroll_by(x, y) leaves the mouse position at the same location relative to the viewport, which is what you seem to expect. So if the mouse position is at coordinates (100, 100) (relative to the viewport) and you then scroll_by(0, 100), the mouse position should still be at coordinates (100, 100) relative to the viewport. If this is not the case, it is a bug. Note that relative to the document, the mouse position now is (100, 200).

If you think you encountered a bug, please specify which browser and which version of that browser you are using.

If you expected different behavior, please provide an example of the commands you use and where you expect the mouse position to be after every command.

For example,:

actions = HLISA_ActionChains(driver) # expected: (0, 0) actually: (0, 0)
actions.move_to(100,100).perform() # expected: (100, 100) actually: (100, 100)
actions.scroll_by(0, 200).perform() # expected: (100, 100) actually: (100, 100) 
actions.move_to(200, 200).perform() # expected: (200, 200) actually: (200, 200)
# (all relative to the viewport)

A code snippet to get the mouse position relative to the viewport:

function trackCursor(e) {
  console.log("A mousemove ended at: (" + e.clientX + ", " + e.clientY + ")");
}

document.addEventListener("mousemove", function(e) {trackCursor(e)});

@psychaos9999
Copy link
Author

My bad, Now I understand how to get the real position of pointer related to viewport, sorry.

Anyway there is a way to start the mouse movement from an arbitrary point inside the viewport, and not always from the origin (0,0)?

Thank you in advance and sorry for my questions

@droefs
Copy link
Owner

droefs commented Sep 12, 2022

Thank you for the interesting question.

Anyway there is a way to start the mouse movement from an arbitrary point inside the viewport, and not always from the origin (0,0)?

Unfortunately, I am not aware of any method do to this. I would be very happy to hear about a method to achieve this, if it exists.

It might be possible to make it look like the mouse starts on an arbitrary point inside the viewport to the website. If the mouse is moved before any JavaScript is parsed by the webbrowser, the browser can not see that the pointer started at (0, 0). It might be possible to implement this by altering the page loading strategy, see for example this question for how the page loading strategy can be altered.

Doing this for pages that are loaded in a manner different to using the .get() function might be very hard.

Also, it only makes it look like the cursor starts at an arbitrary point to the website, but it does not actually start at that location, so I don't know whether this would answer your question.

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

2 participants