Skip to content

Commit 6aa31f3

Browse files
authored
[py] Cleanup and convert more doctrings to google-style (#16503)
1 parent 9564733 commit 6aa31f3

File tree

22 files changed

+332
-532
lines changed

22 files changed

+332
-532
lines changed

py/selenium/webdriver/common/action_chains.py

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ class ActionChains:
6969
def __init__(self, driver: WebDriver, duration: int = 250, devices: list[AnyDevice] | None = None) -> None:
7070
"""Creates a new ActionChains.
7171
72-
:Args:
73-
- driver: The WebDriver instance which performs user actions.
74-
- duration: override the default 250 msecs of DEFAULT_MOVE_DURATION in PointerInput
72+
Args:
73+
driver: The WebDriver instance which performs user actions.
74+
duration: override the default 250 msecs of DEFAULT_MOVE_DURATION in PointerInput
7575
"""
7676
self._driver = driver
7777
mouse = None
@@ -101,9 +101,9 @@ def reset_actions(self) -> None:
101101
def click(self, on_element: WebElement | None = None) -> ActionChains:
102102
"""Clicks an element.
103103
104-
:Args:
105-
- on_element: The element to click.
106-
If None, clicks on current mouse position.
104+
Args:
105+
on_element: The element to click.
106+
If None, clicks on current mouse position.
107107
"""
108108
if on_element:
109109
self.move_to_element(on_element)
@@ -117,9 +117,9 @@ def click(self, on_element: WebElement | None = None) -> ActionChains:
117117
def click_and_hold(self, on_element: WebElement | None = None) -> ActionChains:
118118
"""Holds down the left mouse button on an element.
119119
120-
:Args:
121-
- on_element: The element to mouse down.
122-
If None, clicks on current mouse position.
120+
Args:
121+
on_element: The element to mouse down.
122+
If None, clicks on current mouse position.
123123
"""
124124
if on_element:
125125
self.move_to_element(on_element)
@@ -132,9 +132,9 @@ def click_and_hold(self, on_element: WebElement | None = None) -> ActionChains:
132132
def context_click(self, on_element: WebElement | None = None) -> ActionChains:
133133
"""Performs a context-click (right click) on an element.
134134
135-
:Args:
136-
- on_element: The element to context-click.
137-
If None, clicks on current mouse position.
135+
Args:
136+
on_element: The element to context-click.
137+
If None, clicks on current mouse position.
138138
"""
139139
if on_element:
140140
self.move_to_element(on_element)
@@ -148,9 +148,9 @@ def context_click(self, on_element: WebElement | None = None) -> ActionChains:
148148
def double_click(self, on_element: WebElement | None = None) -> ActionChains:
149149
"""Double-clicks an element.
150150
151-
:Args:
152-
- on_element: The element to double-click.
153-
If None, clicks on current mouse position.
151+
Args:
152+
on_element: The element to double-click.
153+
If None, clicks on current mouse position.
154154
"""
155155
if on_element:
156156
self.move_to_element(on_element)
@@ -165,9 +165,9 @@ def drag_and_drop(self, source: WebElement, target: WebElement) -> ActionChains:
165165
"""Holds down the left mouse button on the source element, then moves
166166
to the target element and releases the mouse button.
167167
168-
:Args:
169-
- source: The element to mouse down.
170-
- target: The element to mouse up.
168+
Args:
169+
source: The element to mouse down.
170+
target: The element to mouse up.
171171
"""
172172
self.click_and_hold(source)
173173
self.release(target)
@@ -177,10 +177,10 @@ def drag_and_drop_by_offset(self, source: WebElement, xoffset: int, yoffset: int
177177
"""Holds down the left mouse button on the source element, then moves
178178
to the target offset and releases the mouse button.
179179
180-
:Args:
181-
- source: The element to mouse down.
182-
- xoffset: X offset to move to.
183-
- yoffset: Y offset to move to.
180+
Args:
181+
source: The element to mouse down.
182+
xoffset: X offset to move to.
183+
yoffset: Y offset to move to.
184184
"""
185185
self.click_and_hold(source)
186186
self.move_by_offset(xoffset, yoffset)
@@ -191,10 +191,10 @@ def key_down(self, value: str, element: WebElement | None = None) -> ActionChain
191191
"""Sends a key press only, without releasing it. Should only be used
192192
with modifier keys (Control, Alt and Shift).
193193
194-
:Args:
195-
- value: The modifier key to send. Values are defined in `Keys` class.
196-
- element: The element to send keys.
197-
If None, sends a key to current focused element.
194+
Args:
195+
value: The modifier key to send. Values are defined in `Keys` class.
196+
element: The element to send keys.
197+
If None, sends a key to current focused element.
198198
199199
Example, pressing ctrl+c::
200200
@@ -211,10 +211,10 @@ def key_down(self, value: str, element: WebElement | None = None) -> ActionChain
211211
def key_up(self, value: str, element: WebElement | None = None) -> ActionChains:
212212
"""Releases a modifier key.
213213
214-
:Args:
215-
- value: The modifier key to send. Values are defined in Keys class.
216-
- element: The element to send keys.
217-
If None, sends a key to current focused element.
214+
Args:
215+
value: The modifier key to send. Values are defined in Keys class.
216+
element: The element to send keys.
217+
If None, sends a key to current focused element.
218218
219219
Example, pressing ctrl+c::
220220
@@ -231,9 +231,9 @@ def key_up(self, value: str, element: WebElement | None = None) -> ActionChains:
231231
def move_by_offset(self, xoffset: int, yoffset: int) -> ActionChains:
232232
"""Moving the mouse to an offset from current mouse position.
233233
234-
:Args:
235-
- xoffset: X offset to move to, as a positive or negative integer.
236-
- yoffset: Y offset to move to, as a positive or negative integer.
234+
Args:
235+
xoffset: X offset to move to, as a positive or negative integer.
236+
yoffset: Y offset to move to, as a positive or negative integer.
237237
"""
238238

239239
self.w3c_actions.pointer_action.move_by(xoffset, yoffset)
@@ -244,8 +244,8 @@ def move_by_offset(self, xoffset: int, yoffset: int) -> ActionChains:
244244
def move_to_element(self, to_element: WebElement) -> ActionChains:
245245
"""Moving the mouse to the middle of an element.
246246
247-
:Args:
248-
- to_element: The WebElement to move to.
247+
Args:
248+
to_element: The WebElement to move to.
249249
"""
250250

251251
self.w3c_actions.pointer_action.move_to(to_element)
@@ -257,10 +257,10 @@ def move_to_element_with_offset(self, to_element: WebElement, xoffset: int, yoff
257257
"""Move the mouse by an offset of the specified element. Offsets are
258258
relative to the in-view center point of the element.
259259
260-
:Args:
261-
- to_element: The WebElement to move to.
262-
- xoffset: X offset to move to, as a positive or negative integer.
263-
- yoffset: Y offset to move to, as a positive or negative integer.
260+
Args:
261+
to_element: The WebElement to move to.
262+
xoffset: X offset to move to, as a positive or negative integer.
263+
yoffset: Y offset to move to, as a positive or negative integer.
264264
"""
265265

266266
self.w3c_actions.pointer_action.move_to(to_element, int(xoffset), int(yoffset))
@@ -279,9 +279,9 @@ def pause(self, seconds: float | int) -> ActionChains:
279279
def release(self, on_element: WebElement | None = None) -> ActionChains:
280280
"""Releasing a held mouse button on an element.
281281
282-
:Args:
283-
- on_element: The element to mouse up.
284-
If None, releases on current mouse position.
282+
Args:
283+
on_element: The element to mouse up.
284+
If None, releases on current mouse position.
285285
"""
286286
if on_element:
287287
self.move_to_element(on_element)
@@ -294,9 +294,9 @@ def release(self, on_element: WebElement | None = None) -> ActionChains:
294294
def send_keys(self, *keys_to_send: str) -> ActionChains:
295295
"""Sends keys to current focused element.
296296
297-
:Args:
298-
- keys_to_send: The keys to send. Modifier keys constants can be found in the
299-
'Keys' class.
297+
Args:
298+
keys_to_send: The keys to send. Modifier keys constants can be found in the
299+
'Keys' class.
300300
"""
301301
typing = keys_to_typing(keys_to_send)
302302

@@ -309,10 +309,10 @@ def send_keys(self, *keys_to_send: str) -> ActionChains:
309309
def send_keys_to_element(self, element: WebElement, *keys_to_send: str) -> ActionChains:
310310
"""Sends keys to an element.
311311
312-
:Args:
313-
- element: The element to send keys.
314-
- keys_to_send: The keys to send. Modifier keys constants can be found in the
315-
'Keys' class.
312+
Args:
313+
element: The element to send keys.
314+
keys_to_send: The keys to send. Modifier keys constants can be found in the
315+
'Keys' class.
316316
"""
317317
self.click(element)
318318
self.send_keys(*keys_to_send)
@@ -322,8 +322,8 @@ def scroll_to_element(self, element: WebElement) -> ActionChains:
322322
"""If the element is outside the viewport, scrolls the bottom of the
323323
element to the bottom of the viewport.
324324
325-
:Args:
326-
- element: Which element to scroll into the viewport.
325+
Args:
326+
element: Which element to scroll into the viewport.
327327
"""
328328

329329
self.w3c_actions.wheel_action.scroll(origin=element)
@@ -333,9 +333,9 @@ def scroll_by_amount(self, delta_x: int, delta_y: int) -> ActionChains:
333333
"""Scrolls by provided amounts with the origin in the top left corner
334334
of the viewport.
335335
336-
:Args:
337-
- delta_x: Distance along X axis to scroll using the wheel. A negative value scrolls left.
338-
- delta_y: Distance along Y axis to scroll using the wheel. A negative value scrolls up.
336+
Args:
337+
delta_x: Distance along X axis to scroll using the wheel. A negative value scrolls left.
338+
delta_y: Distance along Y axis to scroll using the wheel. A negative value scrolls up.
339339
"""
340340

341341
self.w3c_actions.wheel_action.scroll(delta_x=delta_x, delta_y=delta_y)
@@ -348,13 +348,13 @@ def scroll_from_origin(self, scroll_origin: ScrollOrigin, delta_x: int, delta_y:
348348
is not in the viewport, the bottom of the element will first be
349349
scrolled to the bottom of the viewport.
350350
351-
:Args:
352-
- origin: Where scroll originates (viewport or element center) plus provided offsets.
353-
- delta_x: Distance along X axis to scroll using the wheel. A negative value scrolls left.
354-
- delta_y: Distance along Y axis to scroll using the wheel. A negative value scrolls up.
351+
Args:
352+
scroll_origin: Where scroll originates (viewport or element center) plus provided offsets.
353+
delta_x: Distance along X axis to scroll using the wheel. A negative value scrolls left.
354+
delta_y: Distance along Y axis to scroll using the wheel. A negative value scrolls up.
355355
356-
:Raises: If the origin with offset is outside the viewport.
357-
- MoveTargetOutOfBoundsException - If the origin with offset is outside the viewport.
356+
Raises:
357+
MoveTargetOutOfBoundsException: If the origin with offset is outside the viewport.
358358
"""
359359

360360
if not isinstance(scroll_origin, ScrollOrigin):

py/selenium/webdriver/common/alert.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class Alert:
4747
def __init__(self, driver) -> None:
4848
"""Creates a new Alert.
4949
50-
:Args:
51-
- driver: The WebDriver instance which performs user actions.
50+
Args:
51+
driver: The WebDriver instance which performs user actions.
5252
"""
5353
self.driver = driver
5454

@@ -64,17 +64,15 @@ def dismiss(self) -> None:
6464
def accept(self) -> None:
6565
"""Accepts the alert available.
6666
67-
:Usage:
68-
::
69-
70-
Alert(driver).accept() # Confirm a alert dialog.
67+
Example:
68+
Alert(driver).accept() # Confirm a alert dialog.
7169
"""
7270
self.driver.execute(Command.W3C_ACCEPT_ALERT)
7371

7472
def send_keys(self, keysToSend: str) -> None:
7573
"""Send Keys to the Alert.
7674
77-
:Args:
78-
- keysToSend: The text to be sent to Alert.
75+
Args:
76+
keysToSend: The text to be sent to Alert.
7977
"""
8078
self.driver.execute(Command.W3C_SET_ALERT_VALUE, {"value": keys_to_typing(keysToSend), "text": keysToSend})

py/selenium/webdriver/common/log.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ def __init__(self, driver, bidi_session) -> None:
5757
async def mutation_events(self) -> AsyncGenerator[dict[str, Any], None]:
5858
"""Listen for mutation events and emit them as they are found.
5959
60-
:Usage:
61-
::
62-
60+
Example:
6361
async with driver.log.mutation_events() as event:
6462
pages.load("dynamic.html")
6563
driver.find_element(By.ID, "reveal").click()
@@ -101,9 +99,7 @@ async def add_js_error_listener(self) -> AsyncGenerator[dict[str, Any], None]:
10199
"""Listen for JS errors and when the contextmanager exits check if
102100
there were JS Errors.
103101
104-
:Usage:
105-
::
106-
102+
Example:
107103
async with driver.log.add_js_error_listener() as error:
108104
driver.find_element(By.ID, "throwing-mouseover").click()
109105
assert bool(error)
@@ -124,12 +120,10 @@ async def add_js_error_listener(self) -> AsyncGenerator[dict[str, Any], None]:
124120
async def add_listener(self, event_type) -> AsyncGenerator[dict[str, Any], None]:
125121
"""Listen for certain events that are passed in.
126122
127-
:Args:
128-
- event_type: The type of event that we want to look at.
129-
130-
:Usage:
131-
::
123+
Args:
124+
event_type: The type of event that we want to look at.
132125
126+
Example:
133127
async with driver.log.add_listener(Console.log) as messages:
134128
driver.execute_script("console.log('I like cheese')")
135129
assert messages["message"] == "I love cheese"

0 commit comments

Comments
 (0)