Skip to content

Commit d081744

Browse files
committed
Refactor docstrings for clarity and conciseness across multiple files
1 parent ecbe329 commit d081744

File tree

6 files changed

+47
-72
lines changed

6 files changed

+47
-72
lines changed

py/generate_api_module_listing.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
# under the License.
1717

1818

19-
"""This script recursively scans the `selenium` package directory
20-
to find all modules, then generates the `py/docs/source/api.rst`
21-
file containing a listing of all modules in separate sections.
22-
The `api.rst` file is later used by `sphinx-autogen` to generate
23-
sphinx autodoc stub pages used in the Python API documentation.
24-
See `py/tox.ini` for how it is invoked.
19+
"""This script recursively scans the `selenium` package directory and generates an API listing.
20+
21+
Recursively scans the `selenium` package directory to find all modules,
22+
then generates the `py/docs/source/api.rst` file containing a listing of all
23+
modules in separate sections. The `api.rst` file is later used by
24+
`sphinx-autogen` to generate sphinx autodoc stub pages used in the Python API
25+
documentation. See `py/tox.ini` for how it is invoked.
2526
"""
2627

2728
import os

py/selenium/common/exceptions.py

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ class NoSuchAttributeException(WebDriverException):
9191

9292

9393
class NoSuchShadowRootException(WebDriverException):
94-
"""Thrown when trying to access the shadow root of an element when it does
95-
not have a shadow root attached.
96-
"""
94+
"""Thrown when trying to access the shadow root of an element when it does not have a shadow root attached."""
9795

9896

9997
class StaleElementReferenceException(WebDriverException):
@@ -121,11 +119,9 @@ def __init__(
121119

122120

123121
class InvalidElementStateException(WebDriverException):
124-
"""Thrown when a command could not be completed because the element is in
125-
an invalid state.
122+
"""Thrown when a command could not be completed because the element is in an invalid state.
126123
127-
This can be caused by attempting to clear an element that isn't both
128-
editable and resettable.
124+
This can be caused by attempting to clear an element that isn't both editable and resettable.
129125
"""
130126

131127

@@ -159,11 +155,9 @@ class NoAlertPresentException(WebDriverException):
159155

160156

161157
class ElementNotVisibleException(InvalidElementStateException):
162-
"""Thrown when an element is present on the DOM, but it is not visible, and
163-
so is not able to be interacted with.
158+
"""Thrown when an element is present on the DOM, but it is not visible, and so is not able to be interacted with.
164159
165-
Most commonly encountered when trying to click or read text of an
166-
element that is hidden from view.
160+
Most commonly encountered when trying to click or read text of an element that is hidden from view.
167161
"""
168162

169163
def __init__(
@@ -175,9 +169,7 @@ def __init__(
175169

176170

177171
class ElementNotInteractableException(InvalidElementStateException):
178-
"""Thrown when an element is present in the DOM but interactions with that
179-
element will hit another element due to paint order.
180-
"""
172+
"""Thrown when element interactions will hit another element due to paint order."""
181173

182174
def __init__(
183175
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
@@ -195,9 +187,7 @@ class ElementNotSelectableException(InvalidElementStateException):
195187

196188

197189
class InvalidCookieDomainException(WebDriverException):
198-
"""Thrown when attempting to add a cookie under a different domain than the
199-
current URL.
200-
"""
190+
"""Thrown when attempting to add a cookie under a different domain."""
201191

202192

203193
class UnableToSetCookieException(WebDriverException):
@@ -209,23 +199,17 @@ class TimeoutException(WebDriverException):
209199

210200

211201
class MoveTargetOutOfBoundsException(WebDriverException):
212-
"""Thrown when the target provided to the `ActionsChains` move() method is
213-
invalid, i.e. out of document.
214-
"""
202+
"""Thrown when the target provided to the `ActionsChains` move() method is invalid, i.e. out of document."""
215203

216204

217205
class UnexpectedTagNameException(WebDriverException):
218206
"""Thrown when a support class did not get an expected web element."""
219207

220208

221209
class InvalidSelectorException(WebDriverException):
222-
"""Thrown when the selector which is used to find an element does not
223-
return a WebElement.
210+
"""Thrown when the selector used to find an element does not return a WebElement.
224211
225-
Currently this only happens when the selector is an xpath expression
226-
and it is either syntactically invalid (i.e. it is not a xpath
227-
expression) or the expression does not select WebElements (e.g.
228-
"count(//input)").
212+
Currently this only happens when the XPath expression is syntactically invalid or does not select WebElements.
229213
"""
230214

231215
def __init__(
@@ -257,20 +241,15 @@ class JavascriptException(WebDriverException):
257241

258242

259243
class NoSuchCookieException(WebDriverException):
260-
"""No cookie matching the given path name was found amongst the associated
261-
cookies of the current browsing context's active document.
262-
"""
244+
"""Thrown when no cookie matching the given path name was found."""
263245

264246

265247
class ScreenshotException(WebDriverException):
266248
"""A screen capture was made impossible."""
267249

268250

269251
class ElementClickInterceptedException(WebDriverException):
270-
"""The Element Click command could not be completed because the element
271-
receiving the events is obscuring the element that was requested to be
272-
clicked.
273-
"""
252+
"""Thrown when element click fails because another element obscures it."""
274253

275254
def __init__(
276255
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
@@ -281,19 +260,15 @@ def __init__(
281260

282261

283262
class InsecureCertificateException(WebDriverException):
284-
"""Navigation caused the user agent to hit a certificate warning, which is
285-
usually the result of an expired or invalid TLS certificate.
286-
"""
263+
"""Thrown when the user agent hits a certificate warning (expired or invalid TLS certificate)."""
287264

288265

289266
class InvalidCoordinatesException(WebDriverException):
290267
"""The coordinates provided to an interaction's operation are invalid."""
291268

292269

293270
class InvalidSessionIdException(WebDriverException):
294-
"""Occurs if the given session id is not in the list of active sessions,
295-
meaning the session either does not exist or that it's not active.
296-
"""
271+
"""Thrown when the given session id is not in the list of active sessions."""
297272

298273
def __init__(
299274
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
@@ -315,9 +290,7 @@ def __init__(
315290

316291

317292
class UnknownMethodException(WebDriverException):
318-
"""The requested command matched a known URL but did not match any methods
319-
for that URL.
320-
"""
293+
"""The requested command matched a known URL but did not match any methods for that URL."""
321294

322295

323296
class NoSuchDriverException(WebDriverException):

py/selenium/webdriver/chrome/service.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424

2525

2626
class Service(service.ChromiumService):
27-
"""A Service class that is responsible for the starting and stopping of
28-
`chromedriver`.
27+
"""Service class responsible for starting and stopping the chromedriver executable.
2928
3029
Args:
3130
executable_path: Install path of the chromedriver executable, defaults

py/selenium/webdriver/chromium/service.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424

2525

2626
class ChromiumService(service.Service):
27-
"""A Service class that is responsible for the starting and stopping the
28-
WebDriver instance of the ChromiumDriver.
27+
"""Service class responsible for starting and stopping the ChromiumDriver WebDriver instance.
2928
3029
Args:
3130
executable_path: Install path of the executable.

py/selenium/webdriver/common/action_chains.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434

3535

3636
class ActionChains:
37-
"""ActionChains are a way to automate low level interactions such as mouse
37+
"""Automate low-level interactions like mouse movements, button actions, key presses, and context menus.
38+
39+
ActionChains are a way to automate low level interactions such as mouse
3840
movements, mouse button actions, key press, and context menu interactions.
3941
This is useful for doing more complex actions like hover over and drag and
4042
drop.
@@ -94,9 +96,7 @@ def perform(self) -> None:
9496
self.w3c_actions.perform()
9597

9698
def reset_actions(self) -> None:
97-
"""Clears actions that are already stored locally and on the remote
98-
end.
99-
"""
99+
"""Clear actions stored locally and on the remote end."""
100100
self.w3c_actions.clear_actions()
101101
for device in self.w3c_actions.devices:
102102
device.clear_actions()
@@ -165,8 +165,7 @@ def double_click(self, on_element: WebElement | None = None) -> ActionChains:
165165
return self
166166

167167
def drag_and_drop(self, source: WebElement, target: WebElement) -> ActionChains:
168-
"""Holds down the left mouse button on the source element, then moves
169-
to the target element and releases the mouse button.
168+
"""Hold down the left mouse button on an element, then move to target and release.
170169
171170
Args:
172171
source: The element to mouse down.
@@ -177,8 +176,7 @@ def drag_and_drop(self, source: WebElement, target: WebElement) -> ActionChains:
177176
return self
178177

179178
def drag_and_drop_by_offset(self, source: WebElement, xoffset: int, yoffset: int) -> ActionChains:
180-
"""Holds down the left mouse button on the source element, then moves
181-
to the target offset and releases the mouse button.
179+
"""Hold down the left mouse button on an element, then move by offset and release.
182180
183181
Args:
184182
source: The element to mouse down.
@@ -191,8 +189,7 @@ def drag_and_drop_by_offset(self, source: WebElement, xoffset: int, yoffset: int
191189
return self
192190

193191
def key_down(self, value: str, element: WebElement | None = None) -> ActionChains:
194-
"""Sends a key press only, without releasing it. Should only be used
195-
with modifier keys (Control, Alt and Shift).
192+
"""Send a key press only without releasing it (modifier keys only).
196193
197194
Args:
198195
value: The modifier key to send. Values are defined in `Keys` class.
@@ -255,8 +252,9 @@ def move_to_element(self, to_element: WebElement) -> ActionChains:
255252
return self
256253

257254
def move_to_element_with_offset(self, to_element: WebElement, xoffset: int, yoffset: int) -> ActionChains:
258-
"""Move the mouse by an offset of the specified element. Offsets are
259-
relative to the in-view center point of the element.
255+
"""Move the mouse to an element with the specified offsets.
256+
257+
Offsets are relative to the in-view center point of the element.
260258
261259
Args:
262260
to_element: The WebElement to move to.
@@ -318,8 +316,9 @@ def send_keys_to_element(self, element: WebElement, *keys_to_send: str) -> Actio
318316
return self
319317

320318
def scroll_to_element(self, element: WebElement) -> ActionChains:
321-
"""If the element is outside the viewport, scrolls the bottom of the
322-
element to the bottom of the viewport.
319+
"""Scroll the element into the viewport if it's outside it.
320+
321+
Scrolls the bottom of the element to the bottom of the viewport.
323322
324323
Args:
325324
element: Which element to scroll into the viewport.
@@ -328,7 +327,9 @@ def scroll_to_element(self, element: WebElement) -> ActionChains:
328327
return self
329328

330329
def scroll_by_amount(self, delta_x: int, delta_y: int) -> ActionChains:
331-
"""Scrolls by provided amounts with the origin in the top left corner
330+
"""Scroll by a provided amount with the origin in the top left corner.
331+
332+
Scrolls by provided amounts with the origin in the top left corner
332333
of the viewport.
333334
334335
Args:
@@ -339,8 +340,9 @@ def scroll_by_amount(self, delta_x: int, delta_y: int) -> ActionChains:
339340
return self
340341

341342
def scroll_from_origin(self, scroll_origin: ScrollOrigin, delta_x: int, delta_y: int) -> ActionChains:
342-
"""Scrolls by provided amount based on a provided origin. The scroll
343-
origin is either the center of an element or the upper left of the
343+
"""Scroll by a provided amount based on a scroll origin (element or viewport).
344+
345+
The scroll origin is either the center of an element or the upper left of the
344346
viewport plus any offsets. If the origin is an element, and the element
345347
is not in the viewport, the bottom of the element will first be
346348
scrolled to the bottom of the viewport.

py/selenium/webdriver/common/bidi/browsing_context.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,9 @@ def get_tree(
812812
max_depth: Optional[int] = None,
813813
root: Optional[str] = None,
814814
) -> list[BrowsingContextInfo]:
815-
"""Returns a tree of all descendent navigables including the given parent itself, or all top-level contexts
815+
"""Get a tree of all descendent navigables including the given parent itself.
816+
817+
Returns a tree of all descendent navigables including the given parent itself, or all top-level contexts
816818
when no parent is provided.
817819
818820
Args:
@@ -917,8 +919,7 @@ def print(
917919
scale: float = 1.0,
918920
shrink_to_fit: bool = True,
919921
) -> str:
920-
"""Creates a paginated representation of a document, and returns it as a PDF document represented as a
921-
Base64-encoded string.
922+
"""Create a paginated PDF representation of the document as a Base64-encoded string.
922923
923924
Args:
924925
context: The browsing context ID.

0 commit comments

Comments
 (0)