4

I am using Selenium in Chrome with Python to automate some testing and part of that is moving the mouse, as I am creating a lot of test I run them in parallel on threads. The only piece of code that really gives me problems are the following:

action =  selenium.webdriver.common.action_chains.ActionChains(driver)
action.move_by_offset(x,y)
action.perform()

For some reason sometime the above will take at least 5 seconds, e.g. 5.03123 seconds, to execute. When there is a delay it is always only slightly above 5, but never below 5, which leads me to believe that somewhere there is a time.sleep(5). I have checked the selenium actionchains file and commented out:

self.w3c_actions.key_action.pause()

in case this was the culprit, but there has been no significant change.

An important note is that this seems to be a larger problem/occurring more often when my window is minimized and I have multiple threads running.

I am very much at a loss on why this happens, and have tried a bunch of different things/test, but basically to no avail. Any and all help is much appreciated.

If you need any additional information or I should run other specific tests let me know and I will.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
John Doe
  • 83
  • 8

2 Answers2

1

You can override the method:

class ActionChainsChild(ActionChains):
   def move_by_offset(self, xoffset, yoffset):
        """
        Moving the mouse to an offset from current mouse position.

        :Args:
         - xoffset: X offset to move to, as a positive or negative integer.
         - yoffset: Y offset to move to, as a positive or negative integer.
        """
        if self._driver.w3c:
            self.w3c_actions.pointer_action.move_by(xoffset, yoffset)
            #self.w3c_actions.key_action.pause()
        else:
            self._actions.append(lambda: self._driver.execute(
                Command.MOVE_TO, {
                    'xoffset': int(xoffset),
                    'yoffset': int(yoffset)}))
        return self

Practical links :

https://seleniumhq.github.io/selenium/docs/api/py/_modules/selenium/webdriver/common/action_chains.html

https://www.thedigitalcatonline.com/blog/2014/05/19/method-overriding-in-python/

binboum
  • 11
  • 1
-1

You are doing it wrong commenting out the line:

self.w3c_actions.key_action.pause()

In move_by_offset() method the call to key_action.pause() is implemented for a purpose which is Out Of Scope for this question. By all possible means you souldn't change the source client code.

window is minimized

While executing Selenium Tests you need to keep your windows maximized.

You will find a related discussion in Way to open Selenium browser not ovelapping my current browser

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352