Skip to content

Commit 62c5aa1

Browse files
committed
Refactor docstrings for clarity and conciseness in multiple files
1 parent c7a7de5 commit 62c5aa1

File tree

6 files changed

+42
-88
lines changed

6 files changed

+42
-88
lines changed

py/selenium/webdriver/support/expected_conditions.py

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ def _predicate(driver: WebDriver):
7474

7575

7676
def presence_of_element_located(locator: tuple[str, str]) -> Callable[[WebDriverOrWebElement], WebElement]:
77-
"""An expectation for checking that an element is present on the DOM of a
78-
page. This does not necessarily mean that the element is visible.
77+
"""Check that an element is present on the DOM (not necessarily visible).
7978
8079
Args:
8180
locator: Used to find the element.
@@ -97,8 +96,7 @@ def _predicate(driver: WebDriverOrWebElement):
9796

9897

9998
def url_contains(url: str) -> Callable[[WebDriver], bool]:
100-
"""An expectation for checking that the current url contains a case-
101-
sensitive substring.
99+
"""Check that the current url contains a case-sensitive substring.
102100
103101
Args:
104102
url: The fragment of url expected.
@@ -149,8 +147,7 @@ def _predicate(driver: WebDriver):
149147

150148

151149
def url_changes(url: str) -> Callable[[WebDriver], bool]:
152-
"""An expectation for checking the current url is different than a given
153-
string.
150+
"""Check that the current url differs from a given string.
154151
155152
Args:
156153
url: The expected url, which must not be an exact match.
@@ -168,9 +165,7 @@ def _predicate(driver: WebDriver):
168165
def visibility_of_element_located(
169166
locator: tuple[str, str],
170167
) -> Callable[[WebDriverOrWebElement], Union[Literal[False], WebElement]]:
171-
"""An expectation for checking that an element is present on the DOM of a
172-
page and visible. Visibility means that the element is not only displayed
173-
but also has a height and width that is greater than 0.
168+
"""Check that an element is present on the DOM and visible (has size).
174169
175170
Args:
176171
locator: Used to find the element.
@@ -195,11 +190,7 @@ def _predicate(driver: WebDriverOrWebElement):
195190

196191

197192
def visibility_of(element: WebElement) -> Callable[[Any], Union[Literal[False], WebElement]]:
198-
"""An expectation for checking that an element, known to be present on the
199-
DOM of a page, is visible.
200-
201-
Visibility means that the element is not only displayed but also has
202-
a height and width that is greater than 0.
193+
"""Check that an element is visible (present on DOM and has size).
203194
204195
Args:
205196
element: The WebElement to check.
@@ -221,8 +212,7 @@ def _predicate(_):
221212

222213

223214
def _element_if_visible(element: WebElement, visibility: bool = True) -> Union[Literal[False], WebElement]:
224-
"""An expectation for checking that an element, known to be present on the
225-
DOM of a page, is of the expected visibility.
215+
"""Check if an element has the expected visibility state.
226216
227217
Args:
228218
element: The WebElement to check.
@@ -235,8 +225,7 @@ def _element_if_visible(element: WebElement, visibility: bool = True) -> Union[L
235225

236226

237227
def presence_of_all_elements_located(locator: tuple[str, str]) -> Callable[[WebDriverOrWebElement], list[WebElement]]:
238-
"""An expectation for checking that there is at least one element present
239-
on a web page.
228+
"""Check that all elements matching the locator are present on the DOM.
240229
241230
Args:
242231
locator: Used to find the element.
@@ -258,8 +247,7 @@ def _predicate(driver: WebDriverOrWebElement):
258247

259248

260249
def visibility_of_any_elements_located(locator: tuple[str, str]) -> Callable[[WebDriverOrWebElement], list[WebElement]]:
261-
"""An expectation for checking that there is at least one element visible
262-
on a web page.
250+
"""Check that at least one element is visible on the web page.
263251
264252
Args:
265253
locator: Used to find the element.
@@ -283,9 +271,7 @@ def _predicate(driver: WebDriverOrWebElement):
283271
def visibility_of_all_elements_located(
284272
locator: tuple[str, str],
285273
) -> Callable[[WebDriverOrWebElement], Union[list[WebElement], Literal[False]]]:
286-
"""An expectation for checking that all elements are present on the DOM of
287-
a page and visible. Visibility means that the elements are not only
288-
displayed but also has a height and width that is greater than 0.
274+
"""Check that all elements are present on the DOM and visible (have size).
289275
290276
Args:
291277
locator: Used to find the elements.
@@ -314,8 +300,7 @@ def _predicate(driver: WebDriverOrWebElement):
314300

315301

316302
def text_to_be_present_in_element(locator: tuple[str, str], text_: str) -> Callable[[WebDriverOrWebElement], bool]:
317-
"""An expectation for checking if the given text is present in the
318-
specified element.
303+
"""Check that the given text is present in the specified element.
319304
320305
Args:
321306
locator: Used to find the element.
@@ -346,8 +331,7 @@ def _predicate(driver: WebDriverOrWebElement):
346331
def text_to_be_present_in_element_value(
347332
locator: tuple[str, str], text_: str
348333
) -> Callable[[WebDriverOrWebElement], bool]:
349-
"""An expectation for checking if the given text is present in the
350-
element's value.
334+
"""Check that the given text is present in the element's value.
351335
352336
Args:
353337
locator: Used to find the element.
@@ -380,8 +364,7 @@ def _predicate(driver: WebDriverOrWebElement):
380364
def text_to_be_present_in_element_attribute(
381365
locator: tuple[str, str], attribute_: str, text_: str
382366
) -> Callable[[WebDriverOrWebElement], bool]:
383-
"""An expectation for checking if the given text is present in the
384-
element's attribute.
367+
"""Check that the given text is present in the element's attribute.
385368
386369
Args:
387370
locator: Used to find the element.
@@ -415,11 +398,7 @@ def _predicate(driver: WebDriverOrWebElement):
415398
def frame_to_be_available_and_switch_to_it(
416399
locator: Union[tuple[str, str], str, WebElement],
417400
) -> Callable[[WebDriver], bool]:
418-
"""An expectation for checking whether the given frame is available to
419-
switch to.
420-
421-
If the frame is available it switches the given driver to the
422-
specified frame.
401+
"""Check that the given frame is available and switch to it.
423402
424403
Args:
425404
locator: Used to find the frame.
@@ -449,8 +428,7 @@ def _predicate(driver: WebDriver):
449428
def invisibility_of_element_located(
450429
locator: Union[WebElement, tuple[str, str]],
451430
) -> Callable[[WebDriverOrWebElement], Union[WebElement, bool]]:
452-
"""An Expectation for checking that an element is either invisible or not
453-
present on the DOM.
431+
"""Check that an element is either invisible or not present on the DOM.
454432
455433
Args:
456434
locator: Used to find the element.
@@ -492,8 +470,7 @@ def _predicate(driver: WebDriverOrWebElement):
492470
def invisibility_of_element(
493471
element: Union[WebElement, tuple[str, str]],
494472
) -> Callable[[WebDriverOrWebElement], Union[WebElement, bool]]:
495-
"""An Expectation for checking that an element is either invisible or not
496-
present on the DOM.
473+
"""Check that an element is either invisible or not present on the DOM.
497474
498475
Args:
499476
element: Used to find the element.
@@ -515,8 +492,7 @@ def invisibility_of_element(
515492
def element_to_be_clickable(
516493
mark: Union[WebElement, tuple[str, str]],
517494
) -> Callable[[WebDriverOrWebElement], Union[Literal[False], WebElement]]:
518-
"""An Expectation for checking an element is visible and enabled such that
519-
you can click it.
495+
"""Check that an element is visible and enabled so it can be clicked.
520496
521497
Args:
522498
mark: Used to find the element.
@@ -646,8 +622,7 @@ def _predicate(_):
646622
def element_located_selection_state_to_be(
647623
locator: tuple[str, str], is_selected: bool
648624
) -> Callable[[WebDriverOrWebElement], bool]:
649-
"""An expectation to locate an element and check if the selection state
650-
specified is in that state.
625+
"""Check that an element's selection state matches the expected state.
651626
652627
Args:
653628
locator: Used to find the element.
@@ -696,9 +671,8 @@ def _predicate(driver: WebDriver):
696671
return _predicate
697672

698673

699-
def new_window_is_opened(current_handles: list[str]) -> Callable[[WebDriver], bool]:
700-
"""An expectation that a new window will be opened and have the number of
701-
windows handles increase.
674+
def new_window_is_opened(current_handles: set[str]) -> Callable[[WebDriver], bool]:
675+
"""Check that a new window has been opened (window handles count increased).
702676
703677
Args:
704678
current_handles: The current window handles.
@@ -719,9 +693,8 @@ def _predicate(driver: WebDriver):
719693
return _predicate
720694

721695

722-
def alert_is_present() -> Callable[[WebDriver], Union[Alert, Literal[False]]]:
723-
"""An expectation for checking if an alert is currently present and
724-
switching to it.
696+
def alert_is_present() -> Callable[[WebDriver], Union[Alert, bool]]:
697+
"""Check that an alert is present and switch to it.
725698
726699
Returns:
727700
The Alert once it is located.
@@ -745,8 +718,7 @@ def _predicate(driver: WebDriver):
745718

746719

747720
def element_attribute_to_include(locator: tuple[str, str], attribute_: str) -> Callable[[WebDriverOrWebElement], bool]:
748-
"""An expectation for checking if the given attribute is included in the
749-
specified element.
721+
"""Check if the given attribute is included in the specified element.
750722
751723
Args:
752724
locator: Used to find the element.

py/selenium/webdriver/support/relative_locator.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def locate_with(by: ByType, using: str) -> "RelativeBy":
6464

6565

6666
class RelativeBy:
67-
"""Gives the opportunity to find elements based on their relative location
68-
on the page from a root element. It is recommended that you use the helper
69-
function to create it.
67+
"""Find elements based on their relative location from a root element.
68+
69+
It is recommended that you use the helper function to create instances.
7070
7171
Example:
7272
--------
@@ -80,8 +80,7 @@ class RelativeBy:
8080
LocatorType = dict[ByType, str]
8181

8282
def __init__(self, root: Optional[dict[ByType, str]] = None, filters: Optional[list] = None):
83-
"""Creates a new RelativeBy object. It is preferred if you use the
84-
`locate_with` method as this signature could change.
83+
"""Create a RelativeBy object (prefer using `locate_with` instead).
8584
8685
Args:
8786
root: A dict with `By` enum as the key and the search query as the value
@@ -309,9 +308,7 @@ def near(self, element_or_locator: Union[WebElement, LocatorType, None] = None,
309308
return self
310309

311310
def to_dict(self) -> dict:
312-
"""Create a dict that will be passed to the driver to start searching
313-
for the element.
314-
"""
311+
"""Create a dict to be passed to the driver for element searching."""
315312
return {
316313
"relative": {
317314
"root": self.root,

py/selenium/webdriver/support/select.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@
2323

2424
class Select:
2525
def __init__(self, webelement: WebElement) -> None:
26-
"""Constructor. A check is made that the given element is, indeed, a
27-
SELECT tag. If it is not, then an UnexpectedTagNameException is thrown.
26+
"""Constructor. A check is made that the given element is a SELECT tag.
2827
2928
Args:
3029
webelement: SELECT element to wrap
3130
3231
Example:
3332
from selenium.webdriver.support.ui import Select
3433
Select(driver.find_element(By.TAG_NAME, "select")).select_by_index(2)
34+
35+
Raises:
36+
UnexpectedTagNameException: If the element is not a SELECT tag
3537
"""
3638
if webelement.tag_name.lower() != "select":
3739
raise UnexpectedTagNameException(f"Select only works on <select> elements, not on {webelement.tag_name}")
@@ -46,16 +48,12 @@ def options(self) -> list[WebElement]:
4648

4749
@property
4850
def all_selected_options(self) -> list[WebElement]:
49-
"""Returns a list of all selected options belonging to this select
50-
tag.
51-
"""
51+
"""Return a list of all selected options belonging to this select tag."""
5252
return [opt for opt in self.options if opt.is_selected()]
5353

5454
@property
5555
def first_selected_option(self) -> WebElement:
56-
"""The first selected option in this select tag (or the currently
57-
selected option in a normal select).
58-
"""
56+
"""Return the first selected option or the currently selected option."""
5957
for opt in self.options:
6058
if opt.is_selected():
6159
return opt
@@ -87,8 +85,7 @@ def select_by_value(self, value: str) -> None:
8785
raise NoSuchElementException(f"Cannot locate option with value: {value}")
8886

8987
def select_by_index(self, index: int) -> None:
90-
"""Select the option at the given index. This is done by examining the
91-
"index" attribute of an element, and not merely by counting.
88+
"""Select the option at the given index by examining the "index" attribute.
9289
9390
Args:
9491
index: The option at this index will be selected
@@ -185,8 +182,7 @@ def deselect_by_value(self, value: str) -> None:
185182
raise NoSuchElementException(f"Could not locate element with value: {value}")
186183

187184
def deselect_by_index(self, index: int) -> None:
188-
"""Deselect the option at the given index. This is done by examining
189-
the "index" attribute of an element, and not merely by counting.
185+
"""Deselect the option at the given index by examining the "index" attribute.
190186
191187
Args:
192188
index: The option at this index will be deselected

py/selenium/webdriver/webkitgtk/options.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ def __init__(self) -> None:
2929

3030
@property
3131
def binary_location(self) -> str:
32-
"""
33-
Returns:
34-
The location of the browser binary, otherwise an empty string.
35-
"""
32+
"""Return the location of the browser binary or an empty string."""
3633
return self._binary_location
3734

3835
@binary_location.setter
@@ -45,11 +42,8 @@ def binary_location(self, value: str) -> None:
4542
self._binary_location = value
4643

4744
@property
48-
def overlay_scrollbars_enabled(self):
49-
"""
50-
Returns:
51-
Whether overlay scrollbars should be enabled.
52-
"""
45+
def overlay_scrollbars_enabled(self) -> bool:
46+
"""Return whether overlay scrollbars should be enabled."""
5347
return self._overlay_scrollbars_enabled
5448

5549
@overlay_scrollbars_enabled.setter
@@ -61,10 +55,8 @@ def overlay_scrollbars_enabled(self, value) -> None:
6155
"""
6256
self._overlay_scrollbars_enabled = value
6357

64-
def to_capabilities(self):
65-
"""Creates a capabilities with all the options that have been set and
66-
returns a dictionary with everything.
67-
"""
58+
def to_capabilities(self)-> dict:
59+
"""Create a capabilities dictionary with all set options."""
6860
caps = self._caps
6961

7062
browser_options = {}

py/selenium/webdriver/webkitgtk/service.py

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

2727

2828
class Service(service.Service):
29-
"""A Service class that is responsible for the starting and stopping of
30-
`WebKitWebDriver`.
29+
"""A Service class that is responsible for the starting and stopping of `WebKitWebDriver`.
3130
3231
Args:
3332
executable_path: Install path of the WebKitWebDriver executable,

py/selenium/webdriver/webkitgtk/webdriver.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ def __init__(
4949
self._is_remote = False
5050

5151
def quit(self):
52-
"""Closes the browser and shuts down the WebKitGTKDriver executable
53-
that is started when starting the WebKitGTKDriver.
54-
"""
52+
"""Close the browser and shut down the WebKitGTK driver executable."""
5553
try:
5654
super().quit()
5755
except http_client.BadStatusLine:

0 commit comments

Comments
 (0)