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 cursor lose focus when loading or refreshing a new page #21

Open
JingerTea opened this issue Jul 3, 2022 · 5 comments
Open

Mouse cursor lose focus when loading or refreshing a new page #21

JingerTea opened this issue Jul 3, 2022 · 5 comments

Comments

@JingerTea
Copy link

from selenium_toolbox.prep_webdriver import get_driver
from HLISA.hlisa_action_chains import HLISA_ActionChains

driver = get_driver()
driver.get("https://apple.com")

action = HLISA_ActionChains(driver)
action.move_to(100,100).perform()
driver.refresh()
action.move_to(200,200).perform()

In the example code above, the mouse will move from (0,0) to (100,100). When I refresh the page or load a new page, the mouse will take its current position as (0,0). In this case, (100,100) becomes (0,0), which cause the mouse to lose focus. When I perform the second action, it is moving the mouse from (100,100) to (300,300) instead of (0,0) to (200,200).

Is there any line of code that can reset the mouse back to top left corner, and calibrate it back to (0,0)

@JingerTea
Copy link
Author

JingerTea commented Jul 3, 2022

function enableCursor() {
  var seleniumFollowerImg = document.createElement("img");
  seleniumFollowerImg.setAttribute('src', 'data:image/png;base64,'
    + 'iVBORw0KGgoAAAANSUhEUgAAABQAAAAeCAQAAACGG/bgAAAAAmJLR0QA/4ePzL8AAAAJcEhZcwAA'
    + 'HsYAAB7GAZEt8iwAAAAHdElNRQfgAwgMIwdxU/i7AAABZklEQVQ4y43TsU4UURSH8W+XmYwkS2I0'
    + '9CRKpKGhsvIJjG9giQmliHFZlkUIGnEF7KTiCagpsYHWhoTQaiUUxLixYZb5KAAZZhbunu7O/PKf'
    + 'e+fcA+/pqwb4DuximEqXhT4iI8dMpBWEsWsuGYdpZFttiLSSgTvhZ1W/SvfO1CvYdV1kPghV68a3'
    + '0zzUWZH5pBqEui7dnqlFmLoq0gxC1XfGZdoLal2kea8ahLoqKXNAJQBT2yJzwUTVt0bS6ANqy1ga'
    + 'VCEq/oVTtjji4hQVhhnlYBH4WIJV9vlkXLm+10R8oJb79Jl1j9UdazJRGpkrmNkSF9SOz2T71s7M'
    + 'SIfD2lmmfjGSRz3hK8l4w1P+bah/HJLN0sys2JSMZQB+jKo6KSc8vLlLn5ikzF4268Wg2+pPOWW6'
    + 'ONcpr3PrXy9VfS473M/D7H+TLmrqsXtOGctvxvMv2oVNP+Av0uHbzbxyJaywyUjx8TlnPY2YxqkD'
    + 'dAAAAABJRU5ErkJggg==');
  seleniumFollowerImg.setAttribute('id', 'selenium_mouse_follower');
  seleniumFollowerImg.setAttribute('style', 'position: absolute; z-index: 99999999999; pointer-events: none; left:0; top:0');
  document.body.appendChild(seleniumFollowerImg);
  document.onmousemove = function (e) {
    document.getElementById("selenium_mouse_follower").style.left = e.pageX + 'px';
    document.getElementById("selenium_mouse_follower").style.top = e.pageY + 'px';
  };
};

enableCursor();

To see the mouse move in action, you can enter this in chrome's console

@JingerTea
Copy link
Author

A temporarily fix to this is to use the original action chain library to reset mouse location

ActionChains(driver).move_to_location(0,0).perform()

@bkrumnow
Copy link
Collaborator

bkrumnow commented Aug 4, 2022

To the best of my knowledge, we cannot get the mouse position without triggering mouse events (which is a hacky solution and not human-alike).

I think that we want to dive more into Selenium here. If we can grab the current position from Selenium itself, then we have a way to come around this. Alternatively, we should challenge the assumption above.

Side remark: Can we track if the mouse position got a reset?

@droefs
Copy link
Owner

droefs commented Aug 4, 2022

Thank you for reporting this issue and providing a temporary fix JingerTea. We tried to come up with a solution that is human like and a solid permanent solution, but it is hard to come up with a robust solution that works in all cases. We will investigate using the ideas from above and publish and updated version of HLISA when we found a solution.

@droefs
Copy link
Owner

droefs commented Sep 11, 2022

Does this issue still exist in HLISA version 1.5? I cannot reproduce the issue, also not in older versions of HLISA.

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

3 participants