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

Method execute

py/selenium/webdriver/remote/webdriver.py:466–508  ·  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

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