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

Method execute

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

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.

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