MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / execute

Method execute

py/selenium/webdriver/remote/webdriver.py:467–509  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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

Callers 15

start_sessionMethod · 0.95
execute_cdp_cmdMethod · 0.95
getMethod · 0.95
titleMethod · 0.95
execute_scriptMethod · 0.95
execute_async_scriptMethod · 0.95
current_urlMethod · 0.95
page_sourceMethod · 0.95
closeMethod · 0.95
quitMethod · 0.95
current_window_handleMethod · 0.95
window_handlesMethod · 0.95

Calls 6

_start_bidiMethod · 0.95
_wrap_valueMethod · 0.95
_unwrap_valueMethod · 0.95
check_responseMethod · 0.80
executeMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected