Skip to content

Commit 61dc9ec

Browse files
Merge branch 'trunk' into null-support-1
2 parents 3e5f2b4 + a7c0cfb commit 61dc9ec

File tree

3 files changed

+790
-361
lines changed

3 files changed

+790
-361
lines changed

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

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ def __init__(
4949
self.driver = driver
5050

5151
def get_device_with(self, name: str) -> Optional[Union["WheelInput", "PointerInput", "KeyInput"]]:
52+
"""Get the device with the given name.
53+
54+
Parameters:
55+
----------
56+
name : str
57+
The name of the device to get.
58+
59+
Returns:
60+
--------
61+
Optional[Union[WheelInput, PointerInput, KeyInput]] : The device with the given name.
62+
"""
5263
return next(filter(lambda x: x == name, self.devices), None)
5364

5465
@property
@@ -72,21 +83,83 @@ def wheel_action(self) -> WheelActions:
7283
return self._wheel_action
7384

7485
def add_key_input(self, name: str) -> KeyInput:
86+
"""Add a new key input device to the action builder.
87+
88+
Parameters:
89+
----------
90+
name : str
91+
The name of the key input device.
92+
93+
Returns:
94+
--------
95+
KeyInput : The newly created key input device.
96+
97+
Example:
98+
--------
99+
>>> action_builder = ActionBuilder(driver)
100+
>>> action_builder.add_key_input(name="keyboard2")
101+
"""
75102
new_input = KeyInput(name)
76103
self._add_input(new_input)
77104
return new_input
78105

79106
def add_pointer_input(self, kind: str, name: str) -> PointerInput:
107+
"""Add a new pointer input device to the action builder.
108+
109+
Parameters:
110+
----------
111+
kind : str
112+
The kind of pointer input device.
113+
- "mouse"
114+
- "touch"
115+
- "pen"
116+
name : str
117+
The name of the pointer input device.
118+
119+
Returns:
120+
--------
121+
PointerInput : The newly created pointer input device.
122+
123+
Example:
124+
--------
125+
>>> action_builder = ActionBuilder(driver)
126+
>>> action_builder.add_pointer_input(kind="mouse", name="mouse")
127+
"""
80128
new_input = PointerInput(kind, name)
81129
self._add_input(new_input)
82130
return new_input
83131

84132
def add_wheel_input(self, name: str) -> WheelInput:
133+
"""Add a new wheel input device to the action builder.
134+
135+
Parameters:
136+
----------
137+
name : str
138+
The name of the wheel input device.
139+
140+
Returns:
141+
--------
142+
WheelInput : The newly created wheel input device.
143+
144+
Example:
145+
--------
146+
>>> action_builder = ActionBuilder(driver)
147+
>>> action_builder.add_wheel_input(name="wheel2")
148+
"""
85149
new_input = WheelInput(name)
86150
self._add_input(new_input)
87151
return new_input
88152

89153
def perform(self) -> None:
154+
"""Performs all stored actions.
155+
156+
Example:
157+
--------
158+
>>> action_builder = ActionBuilder(driver)
159+
>>> keyboard = action_builder.key_input
160+
>>> el = driver.find_element(id: "some_id")
161+
>>> action_builder.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys('keys').perform()
162+
"""
90163
enc = {"actions": []}
91164
for device in self.devices:
92165
encoded = device.encode()
@@ -96,8 +169,24 @@ def perform(self) -> None:
96169
self.driver.execute(Command.W3C_ACTIONS, enc)
97170

98171
def clear_actions(self) -> None:
99-
"""Clears actions that are already stored on the remote end."""
172+
"""Clears actions that are already stored on the remote end.
173+
174+
Example:
175+
--------
176+
>>> action_builder = ActionBuilder(driver)
177+
>>> keyboard = action_builder.key_input
178+
>>> el = driver.find_element(By.ID, "some_id")
179+
>>> action_builder.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys('keys')
180+
>>> action_builder.clear_actions()
181+
"""
100182
self.driver.execute(Command.W3C_CLEAR_ACTIONS)
101183

102184
def _add_input(self, new_input: Union[KeyInput, PointerInput, WheelInput]) -> None:
185+
"""Add a new input device to the action builder.
186+
187+
Parameters:
188+
----------
189+
new_input : Union[KeyInput, PointerInput, WheelInput]
190+
The new input device to add.
191+
"""
103192
self.devices.append(new_input)

0 commit comments

Comments
 (0)