Skip to content

Commit 3c82c86

Browse files
[Python] Allow overriding the default 250 msecs duration of pointer movement (#9336)
Co-authored-by: David Burns <[email protected]>
1 parent 4162e16 commit 3c82c86

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

py/selenium/webdriver/common/action_chains.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,17 @@ class ActionChains(object):
5656
another.
5757
"""
5858

59-
def __init__(self, driver):
59+
def __init__(self, driver, duration=250):
6060
"""
6161
Creates a new ActionChains.
6262
6363
:Args:
6464
- driver: The WebDriver instance which performs user actions.
65+
- duration: override the default 250 msecs of DEFAULT_MOVE_DURATION in PointerInput
6566
"""
6667
self._driver = driver
6768
self._actions = []
68-
self.w3c_actions = ActionBuilder(driver)
69+
self.w3c_actions = ActionBuilder(driver, duration=duration)
6970

7071
def perform(self):
7172
"""

py/selenium/webdriver/common/actions/action_builder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424

2525

2626
class ActionBuilder(object):
27-
def __init__(self, driver, mouse=None, keyboard=None):
27+
def __init__(self, driver, mouse=None, keyboard=None, duration=250):
2828
if not mouse:
2929
mouse = PointerInput(interaction.POINTER_MOUSE, "mouse")
3030
if not keyboard:
3131
keyboard = KeyInput(interaction.KEY)
3232
self.devices = [mouse, keyboard]
3333
self._key_action = KeyActions(keyboard)
34-
self._pointer_action = PointerActions(mouse)
34+
self._pointer_action = PointerActions(mouse, duration=duration)
3535
self.driver = driver
3636

3737
def get_device_with(self, name):

py/selenium/webdriver/common/actions/pointer_actions.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@
2525

2626
class PointerActions(Interaction):
2727

28-
def __init__(self, source=None):
28+
def __init__(self, source=None, duration=250):
29+
"""
30+
Args:
31+
- source: PointerInput instance
32+
- duration: override the default 250 msecs of DEFAULT_MOVE_DURATION in source
33+
"""
2934
if not source:
3035
source = PointerInput(interaction.POINTER_MOUSE, "mouse")
3136
self.source = source
37+
self._duration = duration
3238
super(PointerActions, self).__init__(source)
3339

3440
def pointer_down(self, button=MouseButton.LEFT):
@@ -49,15 +55,15 @@ def move_to(self, element, x=None, y=None):
4955
else:
5056
left = 0
5157
top = 0
52-
self.source.create_pointer_move(origin=element, x=int(left), y=int(top))
58+
self.source.create_pointer_move(origin=element, duration=self._duration, x=int(left), y=int(top))
5359
return self
5460

5561
def move_by(self, x, y):
56-
self.source.create_pointer_move(origin=interaction.POINTER, x=int(x), y=int(y))
62+
self.source.create_pointer_move(origin=interaction.POINTER, duration=self._duration, x=int(x), y=int(y))
5763
return self
5864

5965
def move_to_location(self, x, y):
60-
self.source.create_pointer_move(origin='viewport', x=int(x), y=int(y))
66+
self.source.create_pointer_move(origin='viewport', duration=self._duration, x=int(x), y=int(y))
6167
return self
6268

6369
def click(self, element=None):

0 commit comments

Comments
 (0)