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,
)
| 453 | return self.execute("executeCdpCommand", {"cmd": cmd, "params": cmd_args})["value"] |
| 454 | |
| 455 | def execute( |
| 456 | self, |
| 457 | driver_command: str | Generator[dict[str, Any], Any, Any], |
| 458 | params: dict[str, Any] | None = None, |
| 459 | ) -> Any: |
| 460 | """Sends a command to be executed by a command.CommandExecutor. |
| 461 | |
| 462 | Args: |
| 463 | driver_command: The name of the command to execute as a string. |
| 464 | Can also be a BiDi protocol command generator. |
| 465 | params: A dictionary of named parameters to send with the command. |
| 466 | Ignored when ``driver_command`` is a BiDi generator. |
| 467 | |
| 468 | Returns: |
| 469 | The command's JSON response loaded into a dictionary object. |
| 470 | """ |
| 471 | # Handle BiDi generator commands |
| 472 | if inspect.isgenerator(driver_command): |
| 473 | # BiDi command: route through the WebSocket connection, not the |
| 474 | # HTTP RemoteConnection which only accepts (command, params) pairs. |
| 475 | if not self._websocket_connection: |
| 476 | self._start_bidi() |
| 477 | assert self._websocket_connection is not None |
| 478 | return self._websocket_connection.execute(driver_command) |
| 479 | |
| 480 | # Legacy WebDriver command: handle normally |
| 481 | params = self._wrap_value(params) |
| 482 | |
| 483 | if self.session_id: |
| 484 | if not params: |
| 485 | params = {"sessionId": self.session_id} |
| 486 | elif "sessionId" not in params: |
| 487 | params["sessionId"] = self.session_id |
| 488 | |
| 489 | response = cast(RemoteConnection, self.command_executor).execute(driver_command, params) |
| 490 | |
| 491 | if response: |
| 492 | self.error_handler.check_response(response) |
| 493 | response["value"] = self._unwrap_value(response.get("value", None)) |
| 494 | return response |
| 495 | # If the server doesn't send a response, assume the command was |
| 496 | # a success |
| 497 | return {"success": 0, "value": None, "sessionId": self.session_id} |
| 498 | |
| 499 | def get(self, url: str) -> None: |
| 500 | """Navigate the browser to the specified URL. |
no test coverage detected