selenium.webdriver.common.bidi.browsing_context

Classes

BrowsingContext(conn)

BiDi implementation of the browsingContext module.

BrowsingContextEvent(event_class, **kwargs)

Base class for browsing context events.

BrowsingContextInfo(context, url, children, ...)

Represents the properties of a navigable.

DownloadWillBeginParams(context, navigation, ...)

Parameters for the downloadWillBegin event.

HistoryUpdatedParams(context, timestamp, url)

Parameters for the historyUpdated event.

NavigationInfo(context, navigation, ...)

Provides details of an ongoing navigation.

ReadinessState()

Represents the stage of document loading at which a navigation command will return.

UserPromptClosedParams(context, accepted, type)

Parameters for the userPromptClosed event.

UserPromptOpenedParams(context, handler, ...)

Parameters for the userPromptOpened event.

UserPromptType()

Represents the possible user prompt types.

class selenium.webdriver.common.bidi.browsing_context.ReadinessState[source]

Represents the stage of document loading at which a navigation command will return.

NONE = 'none'
INTERACTIVE = 'interactive'
COMPLETE = 'complete'
class selenium.webdriver.common.bidi.browsing_context.UserPromptType[source]

Represents the possible user prompt types.

ALERT = 'alert'
BEFORE_UNLOAD = 'beforeunload'
CONFIRM = 'confirm'
PROMPT = 'prompt'
class selenium.webdriver.common.bidi.browsing_context.NavigationInfo(context: str, navigation: str | None, timestamp: int, url: str)[source]

Provides details of an ongoing navigation.

classmethod from_json(json: dict) NavigationInfo[source]

Creates a NavigationInfo instance from a dictionary.

Parameters:

json: A dictionary containing the navigation information.

Returns:

NavigationInfo: A new instance of NavigationInfo.

class selenium.webdriver.common.bidi.browsing_context.BrowsingContextInfo(context: str, url: str, children: list[BrowsingContextInfo] | None, client_window: str, user_context: str, parent: str | None = None, original_opener: str | None = None)[source]

Represents the properties of a navigable.

classmethod from_json(json: dict) BrowsingContextInfo[source]

Creates a BrowsingContextInfo instance from a dictionary.

Parameters:

json: A dictionary containing the browsing context information.

Returns:

BrowsingContextInfo: A new instance of BrowsingContextInfo.

class selenium.webdriver.common.bidi.browsing_context.DownloadWillBeginParams(context: str, navigation: str | None, timestamp: int, url: str, suggested_filename: str)[source]

Parameters for the downloadWillBegin event.

classmethod from_json(json: dict) DownloadWillBeginParams[source]

Creates a DownloadWillBeginParams instance from a dictionary.

Parameters:

json: A dictionary containing the download parameters.

Returns:

DownloadWillBeginParams: A new instance of DownloadWillBeginParams.

class selenium.webdriver.common.bidi.browsing_context.UserPromptOpenedParams(context: str, handler: str, message: str, type: str, default_value: str | None = None)[source]

Parameters for the userPromptOpened event.

classmethod from_json(json: dict) UserPromptOpenedParams[source]

Creates a UserPromptOpenedParams instance from a dictionary.

Parameters:

json: A dictionary containing the user prompt parameters.

Returns:

UserPromptOpenedParams: A new instance of UserPromptOpenedParams.

class selenium.webdriver.common.bidi.browsing_context.UserPromptClosedParams(context: str, accepted: bool, type: str, user_text: str | None = None)[source]

Parameters for the userPromptClosed event.

classmethod from_json(json: dict) UserPromptClosedParams[source]

Creates a UserPromptClosedParams instance from a dictionary.

Parameters:

json: A dictionary containing the user prompt closed parameters.

Returns:

UserPromptClosedParams: A new instance of UserPromptClosedParams.

class selenium.webdriver.common.bidi.browsing_context.HistoryUpdatedParams(context: str, timestamp: int, url: str)[source]

Parameters for the historyUpdated event.

classmethod from_json(json: dict) HistoryUpdatedParams[source]

Creates a HistoryUpdatedParams instance from a dictionary.

Parameters:

json: A dictionary containing the history updated parameters.

Returns:

HistoryUpdatedParams: A new instance of HistoryUpdatedParams.

class selenium.webdriver.common.bidi.browsing_context.BrowsingContextEvent(event_class: str, **kwargs)[source]

Base class for browsing context events.

classmethod from_json(json: dict) BrowsingContextEvent[source]

Creates a BrowsingContextEvent instance from a dictionary.

Parameters:

json: A dictionary containing the event information.

Returns:

BrowsingContextEvent: A new instance of BrowsingContextEvent.

class selenium.webdriver.common.bidi.browsing_context.BrowsingContext(conn)[source]

BiDi implementation of the browsingContext module.

EVENTS = {'context_created': 'browsingContext.contextCreated', 'context_destroyed': 'browsingContext.contextDestroyed', 'dom_content_loaded': 'browsingContext.domContentLoaded', 'download_will_begin': 'browsingContext.downloadWillBegin', 'fragment_navigated': 'browsingContext.fragmentNavigated', 'history_updated': 'browsingContext.historyUpdated', 'load': 'browsingContext.load', 'navigation_aborted': 'browsingContext.navigationAborted', 'navigation_committed': 'browsingContext.navigationCommitted', 'navigation_failed': 'browsingContext.navigationFailed', 'navigation_started': 'browsingContext.navigationStarted', 'user_prompt_closed': 'browsingContext.userPromptClosed', 'user_prompt_opened': 'browsingContext.userPromptOpened'}
activate(context: str) None[source]

Activates and focuses the given top-level traversable.

Parameters:

context: The browsing context ID to activate.

Raises:

Exception: If the browsing context is not a top-level traversable.

capture_screenshot(context: str, origin: str = 'viewport', format: dict | None = None, clip: dict | None = None) str[source]

Captures an image of the given navigable, and returns it as a Base64-encoded string.

Parameters:

context: The browsing context ID to capture. origin: The origin of the screenshot, either “viewport” or “document”. format: The format of the screenshot. clip: The clip rectangle of the screenshot.

Returns:

str: The Base64-encoded screenshot.

close(context: str, prompt_unload: bool = False) None[source]

Closes a top-level traversable.

Parameters:

context: The browsing context ID to close. prompt_unload: Whether to prompt to unload.

Raises:

Exception: If the browsing context is not a top-level traversable.

create(type: str, reference_context: str | None = None, background: bool = False, user_context: str | None = None) str[source]

Creates a new navigable, either in a new tab or in a new window, and returns its navigable id.

Parameters:

type: The type of the new navigable, either “tab” or “window”. reference_context: The reference browsing context ID. background: Whether to create the new navigable in the background. user_context: The user context ID.

Returns:

str: The browsing context ID of the created navigable.

get_tree(max_depth: int | None = None, root: str | None = None) list[BrowsingContextInfo][source]

Returns a tree of all descendent navigables including the given parent itself, or all top-level contexts when no parent is provided.

Parameters:

max_depth: The maximum depth of the tree. root: The root browsing context ID.

Returns:

List[BrowsingContextInfo]: A list of browsing context information.

handle_user_prompt(context: str, accept: bool | None = None, user_text: str | None = None) None[source]

Allows closing an open prompt.

Parameters:

context: The browsing context ID. accept: Whether to accept the prompt. user_text: The text to enter in the prompt.

locate_nodes(context: str, locator: dict, max_node_count: int | None = None, serialization_options: dict | None = None, start_nodes: list[dict] | None = None) list[dict][source]

Returns a list of all nodes matching the specified locator.

Parameters:

context: The browsing context ID. locator: The locator to use. max_node_count: The maximum number of nodes to return. serialization_options: The serialization options. start_nodes: The start nodes.

Returns:

List[Dict]: A list of nodes.

navigate(context: str, url: str, wait: str | None = None) dict[source]

Navigates a navigable to the given URL.

Parameters:

context: The browsing context ID. url: The URL to navigate to. wait: The readiness state to wait for.

Returns:

Dict: A dictionary containing the navigation result.

print(context: str, background: bool = False, margin: dict | None = None, orientation: str = 'portrait', page: dict | None = None, page_ranges: list[int | str] | None = None, scale: float = 1.0, shrink_to_fit: bool = True) str[source]

Creates a paginated representation of a document, and returns it as a PDF document represented as a Base64-encoded string.

Parameters:

context: The browsing context ID. background: Whether to include the background. margin: The margin parameters. orientation: The orientation, either “portrait” or “landscape”. page: The page parameters. page_ranges: The page ranges. scale: The scale. shrink_to_fit: Whether to shrink to fit.

Returns:

str: The Base64-encoded PDF document.

reload(context: str, ignore_cache: bool | None = None, wait: str | None = None) dict[source]

Reloads a navigable.

Parameters:

context: The browsing context ID. ignore_cache: Whether to ignore the cache. wait: The readiness state to wait for.

Returns:

Dict: A dictionary containing the navigation result.

set_viewport(context: str | None = None, viewport: dict | None = None, device_pixel_ratio: float | None = None, user_contexts: list[str] | None = None) None[source]

Modifies specific viewport characteristics on the given top-level traversable.

Parameters:

context: The browsing context ID. viewport: The viewport parameters. device_pixel_ratio: The device pixel ratio. user_contexts: The user context IDs.

Raises:

Exception: If the browsing context is not a top-level traversable.

traverse_history(context: str, delta: int) dict[source]

Traverses the history of a given navigable by a delta.

Parameters:

context: The browsing context ID. delta: The delta to traverse by.

Returns:

Dict: A dictionary containing the traverse history result.

add_event_handler(event: str, callback: Callable, contexts: list[str] | None = None) int[source]

Add an event handler to the browsing context.

Parameters:

event: The event to subscribe to. callback: The callback function to execute on event. contexts: The browsing context IDs to subscribe to.

Returns:

int: callback id

remove_event_handler(event: str, callback_id: int) None[source]

Remove an event handler from the browsing context.

Parameters:

event: The event to unsubscribe from. callback_id: The callback id to remove.

clear_event_handlers() None[source]

Clear all event handlers from the browsing context.