Sends a command to be executed by a command.CommandExecutor. Args: driver_command: The name of the command to execute as a string. Can also be a BiDi protocol command generator. params: A dictionary of named parameters to send with the command.
(
self,
driver_command: str | Generator[dict[str, Any], Any, Any],
params: dict[str, Any] | None = None,
)
| 530 | return self.execute("executeCdpCommand", {"cmd": cmd, "params": cmd_args})["value"] |
| 531 | |
| 532 | def execute( |
| 533 | self, |
| 534 | driver_command: str | Generator[dict[str, Any], Any, Any], |
| 535 | params: dict[str, Any] | None = None, |
| 536 | ) -> Any: |
| 537 | """Sends a command to be executed by a command.CommandExecutor. |
| 538 | |
| 539 | Args: |
| 540 | driver_command: The name of the command to execute as a string. |
| 541 | Can also be a BiDi protocol command generator. |
| 542 | params: A dictionary of named parameters to send with the command. |
| 543 | Ignored when ``driver_command`` is a BiDi generator. |
| 544 | |
| 545 | Returns: |
| 546 | The command's JSON response loaded into a dictionary object. |
| 547 | """ |
| 548 | # Handle BiDi generator commands |
| 549 | if inspect.isgenerator(driver_command): |
| 550 | # BiDi command: route through the WebSocket connection, not the |
| 551 | # HTTP RemoteConnection which only accepts (command, params) pairs. |
| 552 | if not self._websocket_connection: |
| 553 | self._start_bidi() |
| 554 | assert self._websocket_connection is not None |
| 555 | return self._websocket_connection.execute(driver_command) |
| 556 | |
| 557 | # Legacy WebDriver command: handle normally |
| 558 | params = self._wrap_value(params) |
| 559 | |
| 560 | if self.session_id: |
| 561 | if not params: |
| 562 | params = {"sessionId": self.session_id} |
| 563 | elif "sessionId" not in params: |
| 564 | params["sessionId"] = self.session_id |
| 565 | |
| 566 | response = cast(RemoteConnection, self.command_executor).execute(driver_command, params) |
| 567 | |
| 568 | if response: |
| 569 | self.error_handler.check_response(response) |
| 570 | response["value"] = self._unwrap_value(response.get("value", None)) |
| 571 | return response |
| 572 | # If the server doesn't send a response, assume the command was |
| 573 | # a success |
| 574 | return {"success": 0, "value": None, "sessionId": self.session_id} |
| 575 | |
| 576 | def get(self, url: str) -> None: |
| 577 | """Navigate the browser to the specified URL. |
no test coverage detected