selenium.webdriver.common.bidi.browsing_context¶
Classes
|
BiDi implementation of the browsingContext module. |
|
Represents the properties of a navigable. |
Event class for browsingContext.contextCreated event. |
|
Event class for browsingContext.contextDestroyed event. |
|
Event class for browsingContext.domContentLoaded event. |
|
Event class for browsingContext.downloadWillBegin event. |
|
|
Parameters for the downloadWillBegin event. |
|
|
Event class for browsingContext.fragmentNavigated event. |
|
Event class for browsingContext.historyUpdated event. |
|
|
Parameters for the historyUpdated event. |
|
Event class for browsingContext.load event. |
Event class for browsingContext.navigationAborted event. |
|
Event class for browsingContext.navigationCommitted event. |
|
Event class for browsingContext.navigationFailed event. |
|
|
Provides details of an ongoing navigation. |
Event class for browsingContext.navigationStarted event. |
|
Represents the stage of document loading at which a navigation command will return. |
|
Event class for browsingContext.userPromptClosed event. |
|
|
Parameters for the userPromptClosed event. |
Event class for browsingContext.userPromptOpened event. |
|
|
Parameters for the userPromptOpened event. |
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'¶
Provides details of an ongoing navigation.
- 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.ContextCreated[source]¶
Event class for browsingContext.contextCreated event.
- event_class = 'browsingContext.contextCreated'¶
- class selenium.webdriver.common.bidi.browsing_context.ContextDestroyed[source]¶
Event class for browsingContext.contextDestroyed event.
- event_class = 'browsingContext.contextDestroyed'¶
Event class for browsingContext.navigationStarted event.
Event class for browsingContext.navigationCommitted event.
Event class for browsingContext.navigationFailed event.
Event class for browsingContext.navigationAborted event.
- class selenium.webdriver.common.bidi.browsing_context.DomContentLoaded[source]¶
Event class for browsingContext.domContentLoaded event.
- event_class = 'browsingContext.domContentLoaded'¶
- class selenium.webdriver.common.bidi.browsing_context.Load[source]¶
Event class for browsingContext.load event.
- event_class = 'browsingContext.load'¶
Event class for browsingContext.fragmentNavigated event.
- class selenium.webdriver.common.bidi.browsing_context.DownloadWillBegin[source]¶
Event class for browsingContext.downloadWillBegin event.
- event_class = 'browsingContext.downloadWillBegin'¶
- class selenium.webdriver.common.bidi.browsing_context.UserPromptOpened[source]¶
Event class for browsingContext.userPromptOpened event.
- event_class = 'browsingContext.userPromptOpened'¶
- class selenium.webdriver.common.bidi.browsing_context.UserPromptClosed[source]¶
Event class for browsingContext.userPromptClosed event.
- event_class = 'browsingContext.userPromptClosed'¶
- class selenium.webdriver.common.bidi.browsing_context.HistoryUpdated[source]¶
Event class for browsingContext.historyUpdated event.
- event_class = 'browsingContext.historyUpdated'¶
- class selenium.webdriver.common.bidi.browsing_context.EventConfig(event_key: str, bidi_event: str, event_class: type)[source]¶
- event_key: str¶
- bidi_event: str¶
- event_class: type¶
- class selenium.webdriver.common.bidi.browsing_context.BrowsingContext(conn)[source]¶
BiDi implementation of the browsingContext module.
- EVENT_CONFIGS = {'context_created': EventConfig(event_key='context_created', bidi_event='browsingContext.contextCreated', event_class=<class 'selenium.webdriver.common.bidi.browsing_context.ContextCreated'>), 'context_destroyed': EventConfig(event_key='context_destroyed', bidi_event='browsingContext.contextDestroyed', event_class=<class 'selenium.webdriver.common.bidi.browsing_context.ContextDestroyed'>), 'dom_content_loaded': EventConfig(event_key='dom_content_loaded', bidi_event='browsingContext.domContentLoaded', event_class=<class 'selenium.webdriver.common.bidi.browsing_context.DomContentLoaded'>), 'download_will_begin': EventConfig(event_key='download_will_begin', bidi_event='browsingContext.downloadWillBegin', event_class=<class 'selenium.webdriver.common.bidi.browsing_context.DownloadWillBegin'>), 'fragment_navigated': EventConfig(event_key='fragment_navigated', bidi_event='browsingContext.fragmentNavigated', event_class=<class 'selenium.webdriver.common.bidi.browsing_context.FragmentNavigated'>), 'history_updated': EventConfig(event_key='history_updated', bidi_event='browsingContext.historyUpdated', event_class=<class 'selenium.webdriver.common.bidi.browsing_context.HistoryUpdated'>), 'load': EventConfig(event_key='load', bidi_event='browsingContext.load', event_class=<class 'selenium.webdriver.common.bidi.browsing_context.Load'>), 'navigation_aborted': EventConfig(event_key='navigation_aborted', bidi_event='browsingContext.navigationAborted', event_class=<class 'selenium.webdriver.common.bidi.browsing_context.NavigationAborted'>), 'navigation_committed': EventConfig(event_key='navigation_committed', bidi_event='browsingContext.navigationCommitted', event_class=<class 'selenium.webdriver.common.bidi.browsing_context.NavigationCommitted'>), 'navigation_failed': EventConfig(event_key='navigation_failed', bidi_event='browsingContext.navigationFailed', event_class=<class 'selenium.webdriver.common.bidi.browsing_context.NavigationFailed'>), 'navigation_started': EventConfig(event_key='navigation_started', bidi_event='browsingContext.navigationStarted', event_class=<class 'selenium.webdriver.common.bidi.browsing_context.NavigationStarted'>), 'user_prompt_closed': EventConfig(event_key='user_prompt_closed', bidi_event='browsingContext.userPromptClosed', event_class=<class 'selenium.webdriver.common.bidi.browsing_context.UserPromptClosed'>), 'user_prompt_opened': EventConfig(event_key='user_prompt_opened', bidi_event='browsingContext.userPromptOpened', event_class=<class 'selenium.webdriver.common.bidi.browsing_context.UserPromptOpened'>)}¶
- classmethod get_event_names() list[str] [source]¶
Get a list of all available event names.
Returns:¶
List[str]: A list of event names that can be used with event handlers.
- 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.
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