Skip to content

Commit 8db0490

Browse files
committed
refactor: update documentation format in ErrorHandler and SwitchTo classes
1 parent 53f160e commit 8db0490

File tree

2 files changed

+24
-37
lines changed

2 files changed

+24
-37
lines changed

py/selenium/webdriver/remote/errorhandler.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353

5454

5555
class ExceptionMapping:
56-
"""
57-
:Maps each errorcode in ErrorCode object to corresponding exception
58-
Please refer to https://www.w3.org/TR/webdriver2/#errors for w3c specification
56+
"""Maps each errorcode in ErrorCode object to corresponding exception.
57+
58+
Please refer to https://www.w3.org/TR/webdriver2/#errors for w3c specification.
5959
"""
6060

6161
NO_SUCH_ELEMENT = NoSuchElementException
@@ -146,11 +146,12 @@ def check_response(self, response: dict[str, Any]) -> None:
146146
"""Checks that a JSON response from the WebDriver does not have an
147147
error.
148148
149-
:Args:
150-
- response - The JSON response from the WebDriver server as a dictionary
151-
object.
149+
Args:
150+
response: The JSON response from the WebDriver server as a dictionary
151+
object.
152152
153-
:Raises: If the response contains an error message.
153+
Raises:
154+
WebDriverException: If the response contains an error message.
154155
"""
155156
status = response.get("status", None)
156157
if not status or status == ErrorCode.SUCCESS:

py/selenium/webdriver/remote/switch_to.py

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,17 @@ def __init__(self, driver) -> None:
3434
def active_element(self) -> WebElement:
3535
"""Returns the element with focus, or BODY if nothing has focus.
3636
37-
:Usage:
38-
::
39-
40-
element = driver.switch_to.active_element
37+
Example:
38+
element = driver.switch_to.active_element
4139
"""
4240
return self._driver.execute(Command.W3C_GET_ACTIVE_ELEMENT)["value"]
4341

4442
@property
4543
def alert(self) -> Alert:
4644
"""Switches focus to an alert on the page.
4745
48-
:Usage:
49-
::
50-
51-
alert = driver.switch_to.alert
46+
Example:
47+
alert = driver.switch_to.alert
5248
"""
5349
alert = Alert(self._driver)
5450
_ = alert.text
@@ -57,24 +53,20 @@ def alert(self) -> Alert:
5753
def default_content(self) -> None:
5854
"""Switch focus to the default frame.
5955
60-
:Usage:
61-
::
62-
63-
driver.switch_to.default_content()
56+
Example:
57+
driver.switch_to.default_content()
6458
"""
6559
self._driver.execute(Command.SWITCH_TO_FRAME, {"id": None})
6660

6761
def frame(self, frame_reference: Union[str, int, WebElement]) -> None:
6862
"""Switches focus to the specified frame, by index, name, or
6963
webelement.
7064
71-
:Args:
72-
- frame_reference: The name of the window to switch to, an integer representing the index,
73-
or a webelement that is an (i)frame to switch to.
74-
75-
:Usage:
76-
::
65+
Args:
66+
frame_reference: The name of the window to switch to, an integer representing the index,
67+
or a webelement that is an (i)frame to switch to.
7768
69+
Example:
7870
driver.switch_to.frame("frame_name")
7971
driver.switch_to.frame(1)
8072
driver.switch_to.frame(driver.find_elements(By.TAG_NAME, "iframe")[0])
@@ -96,9 +88,7 @@ def new_window(self, type_hint: Optional[str] = None) -> None:
9688
The type hint can be one of "tab" or "window". If not specified the
9789
browser will automatically select it.
9890
99-
:Usage:
100-
::
101-
91+
Example:
10292
driver.switch_to.new_window("tab")
10393
"""
10494
value = self._driver.execute(Command.NEW_WINDOW, {"type": type_hint})["value"]
@@ -108,23 +98,19 @@ def parent_frame(self) -> None:
10898
"""Switches focus to the parent context. If the current context is the
10999
top level browsing context, the context remains unchanged.
110100
111-
:Usage:
112-
::
113-
101+
Example:
114102
driver.switch_to.parent_frame()
115103
"""
116104
self._driver.execute(Command.SWITCH_TO_PARENT_FRAME)
117105

118106
def window(self, window_name: str) -> None:
119107
"""Switches focus to the specified window.
120108
121-
:Args:
122-
- window_name: The name or window handle of the window to switch to.
123-
124-
:Usage:
125-
::
109+
Args:
110+
window_name: The name or window handle of the window to switch to.
126111
127-
driver.switch_to.window("main")
112+
Example:
113+
driver.switch_to.window("main")
128114
"""
129115
self._w3c_window(window_name)
130116

0 commit comments

Comments
 (0)