Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
d4d8ed0
refactor: update docstrings in WebDriverWait class for clarity and co…
iampopovich Oct 25, 2025
70b8390
refactor: update parameter documentation to use 'Args' format for con…
iampopovich Oct 25, 2025
d7b724a
refactor: update Safari options documentation for clarity and consist…
iampopovich Oct 25, 2025
433f239
refactor: update docstrings in WebElement class for clarity and consi…
iampopovich Oct 25, 2025
c4efb21
refactor: update docstrings in ActionBuilder class to use 'Args' form…
iampopovich Oct 25, 2025
6fc32e7
refactor: update parameter documentation to use 'Args' format for con…
iampopovich Oct 25, 2025
e82648f
refactor: update parameter documentation to use 'Args' format for con…
iampopovich Oct 25, 2025
a14f153
refactor: update parameter documentation to use 'Args' format for con…
iampopovich Oct 25, 2025
7fbf4bb
refactor: update parameter documentation to use 'Args' format for con…
iampopovich Oct 25, 2025
673b50d
refactor: standardize parameter and variable naming conventions acros…
iampopovich Oct 25, 2025
26a5345
fix: correct return type in documentation for BaseOptions getter method
iampopovich Oct 26, 2025
16a713c
Merge branch 'trunk' into feat/pretty-properties-docstrings
iampopovich Oct 26, 2025
235608f
Merge branch 'trunk' into feat/pretty-properties-docstrings
cgoldberg Oct 26, 2025
b51d2a7
fix tests: remove unnecessary WebElement type hints from find_element…
iampopovich Oct 26, 2025
d665c5b
Merge branch 'trunk' into feat/pretty-properties-docstrings
cgoldberg Oct 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 31 additions & 54 deletions py/selenium/webdriver/common/actions/action_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,11 @@ def __init__(
def get_device_with(self, name: str) -> Optional[Union["WheelInput", "PointerInput", "KeyInput"]]:
"""Get the device with the given name.

Parameters:
-----------
name : str
The name of the device to get.
Args:
name: The name of the device to get.

Returns:
--------
Optional[Union[WheelInput, PointerInput, KeyInput]] : The device with the given name.
The device with the given name, or None if not found.
"""
return next(filter(lambda x: x == name, self.devices), None)

Expand All @@ -83,19 +80,15 @@ def wheel_action(self) -> WheelActions:
def add_key_input(self, name: str) -> KeyInput:
"""Add a new key input device to the action builder.

Parameters:
-----------
name : str
The name of the key input device.
Args:
name: The name of the key input device.

Returns:
--------
KeyInput : The newly created key input device.
The newly created key input device.

Example:
--------
>>> action_builder = ActionBuilder(driver)
>>> action_builder.add_key_input(name="keyboard2")
>>> action_builder = ActionBuilder(driver)
>>> action_builder.add_key_input(name="keyboard2")
"""
new_input = KeyInput(name)
self._add_input(new_input)
Expand All @@ -104,25 +97,17 @@ def add_key_input(self, name: str) -> KeyInput:
def add_pointer_input(self, kind: str, name: str) -> PointerInput:
"""Add a new pointer input device to the action builder.

Parameters:
-----------
kind : str
The kind of pointer input device.
- "mouse"
- "touch"
- "pen"

name : str
The name of the pointer input device.
Args:
kind: The kind of pointer input device. Valid values are "mouse",
"touch", or "pen".
name: The name of the pointer input device.

Returns:
--------
PointerInput : The newly created pointer input device.
The newly created pointer input device.

Example:
--------
>>> action_builder = ActionBuilder(driver)
>>> action_builder.add_pointer_input(kind="mouse", name="mouse")
>>> action_builder = ActionBuilder(driver)
>>> action_builder.add_pointer_input(kind="mouse", name="mouse")
"""
new_input = PointerInput(kind, name)
self._add_input(new_input)
Expand All @@ -131,19 +116,15 @@ def add_pointer_input(self, kind: str, name: str) -> PointerInput:
def add_wheel_input(self, name: str) -> WheelInput:
"""Add a new wheel input device to the action builder.

Parameters:
-----------
name : str
The name of the wheel input device.
Args:
name: The name of the wheel input device.

Returns:
--------
WheelInput : The newly created wheel input device.
The newly created wheel input device.

Example:
--------
>>> action_builder = ActionBuilder(driver)
>>> action_builder.add_wheel_input(name="wheel2")
>>> action_builder = ActionBuilder(driver)
>>> action_builder.add_wheel_input(name="wheel2")
"""
new_input = WheelInput(name)
self._add_input(new_input)
Expand All @@ -153,11 +134,10 @@ def perform(self) -> None:
"""Performs all stored actions.

Example:
--------
>>> action_builder = ActionBuilder(driver)
>>> keyboard = action_builder.key_input
>>> el = driver.find_element(id: "some_id")
>>> action_builder.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys("keys").perform()
>>> action_builder = ActionBuilder(driver)
>>> keyboard = action_builder.key_input
>>> el = driver.find_element(id: "some_id")
>>> action_builder.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys("keys").perform()
"""
enc: dict[str, list[Any]] = {"actions": []}
for device in self.devices:
Expand All @@ -171,21 +151,18 @@ def clear_actions(self) -> None:
"""Clears actions that are already stored on the remote end.

Example:
--------
>>> action_builder = ActionBuilder(driver)
>>> keyboard = action_builder.key_input
>>> el = driver.find_element(By.ID, "some_id")
>>> action_builder.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys("keys")
>>> action_builder.clear_actions()
>>> action_builder = ActionBuilder(driver)
>>> keyboard = action_builder.key_input
>>> el = driver.find_element(By.ID, "some_id")
>>> action_builder.click(el).pause(keyboard).pause(keyboard).pause(keyboard).send_keys("keys")
>>> action_builder.clear_actions()
"""
self.driver.execute(Command.W3C_CLEAR_ACTIONS)

def _add_input(self, new_input: Union[KeyInput, PointerInput, WheelInput]) -> None:
"""Add a new input device to the action builder.

Parameters:
-----------
new_input : Union[KeyInput, PointerInput, WheelInput]
The new input device to add.
Args:
new_input: The new input device to add.
"""
self.devices.append(new_input)
34 changes: 9 additions & 25 deletions py/selenium/webdriver/common/bidi/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def get_state(self) -> str:
"""Gets the state of the client window.

Returns:
-------
str: The state of the client window (one of the ClientWindowState constants).
"""
return self.state
Expand All @@ -68,7 +67,6 @@ def get_client_window(self) -> str:
"""Gets the client window identifier.

Returns:
-------
str: The client window identifier.
"""
return self.client_window
Expand All @@ -77,7 +75,6 @@ def get_width(self) -> int:
"""Gets the width of the client window.

Returns:
-------
int: The width of the client window.
"""
return self.width
Expand All @@ -86,7 +83,6 @@ def get_height(self) -> int:
"""Gets the height of the client window.

Returns:
-------
int: The height of the client window.
"""
return self.height
Expand All @@ -95,7 +91,6 @@ def get_x(self) -> int:
"""Gets the x coordinate of the client window.

Returns:
-------
int: The x coordinate of the client window.
"""
return self.x
Expand All @@ -104,7 +99,6 @@ def get_y(self) -> int:
"""Gets the y coordinate of the client window.

Returns:
-------
int: The y coordinate of the client window.
"""
return self.y
Expand All @@ -113,7 +107,6 @@ def is_active(self) -> bool:
"""Checks if the client window is active.

Returns:
-------
bool: True if the client window is active, False otherwise.
"""
return self.active
Expand All @@ -122,16 +115,13 @@ def is_active(self) -> bool:
def from_dict(cls, data: dict) -> "ClientWindowInfo":
"""Creates a ClientWindowInfo instance from a dictionary.

Parameters:
-----------
Args:
data: A dictionary containing the client window information.

Returns:
-------
ClientWindowInfo: A new instance of ClientWindowInfo.

Raises:
------
ValueError: If required fields are missing or have invalid types.
"""
try:
Expand Down Expand Up @@ -175,7 +165,7 @@ def from_dict(cls, data: dict) -> "ClientWindowInfo":
active=active,
)
except (KeyError, TypeError) as e:
raise ValueError(f"Invalid data format for ClientWindowInfo: {e}")
raise ValueError(f"Invalid data format for ClientWindowInfo: {e}") from e


class Browser:
Expand All @@ -194,14 +184,12 @@ def create_user_context(
) -> str:
"""Creates a new user context.

Parameters:
-----------
accept_insecure_certs: Optional flag to accept insecure TLS certificates
proxy: Optional proxy configuration for the user context
unhandled_prompt_behavior: Optional configuration for handling user prompts
Args:
accept_insecure_certs: Optional flag to accept insecure TLS certificates.
proxy: Optional proxy configuration for the user context.
unhandled_prompt_behavior: Optional configuration for handling user prompts.

Returns:
-------
str: The ID of the created user context.
"""
params: dict[str, Any] = {}
Expand All @@ -222,7 +210,6 @@ def get_user_contexts(self) -> list[str]:
"""Gets all user contexts.

Returns:
-------
List[str]: A list of user context IDs.
"""
result = self.conn.execute(command_builder("browser.getUserContexts", {}))
Expand All @@ -231,16 +218,14 @@ def get_user_contexts(self) -> list[str]:
def remove_user_context(self, user_context_id: str) -> None:
"""Removes a user context.

Parameters:
-----------
Args:
user_context_id: The ID of the user context to remove.

Raises:
------
Exception: If the user context ID is "default" or does not exist.
ValueError: If the user context ID is "default" or does not exist.
"""
if user_context_id == "default":
raise Exception("Cannot remove the default user context")
raise ValueError("Cannot remove the default user context")

params = {"userContext": user_context_id}
self.conn.execute(command_builder("browser.removeUserContext", params))
Expand All @@ -249,7 +234,6 @@ def get_client_windows(self) -> list[ClientWindowInfo]:
"""Gets all client windows.

Returns:
-------
List[ClientWindowInfo]: A list of client window information.
"""
result = self.conn.execute(command_builder("browser.getClientWindows", {}))
Expand Down
Loading