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

Method execute_script

py/selenium/webdriver/remote/webdriver.py:656–680  ·  view source on GitHub ↗

Synchronously Executes JavaScript in the current window/frame. Args: script: The javascript to execute. *args: Any applicable arguments for your JavaScript. Example: ``` id = "username" value = "test_user" driv

(self, script: str, *args)

Source from the content-addressed store, hash-verified

654 return list(self.pinned_scripts)
655
656 def execute_script(self, script: str, *args) -> Any:
657 """Synchronously Executes JavaScript in the current window/frame.
658
659 Args:
660 script: The javascript to execute.
661 *args: Any applicable arguments for your JavaScript.
662
663 Example:
664 ```
665 id = "username"
666 value = "test_user"
667 driver.execute_script("document.getElementById(arguments[0]).value = arguments[1];", id, value)
668 ```
669 """
670 if isinstance(script, ScriptKey):
671 script_id = script.id
672 try:
673 script = self.pinned_scripts[script_id]
674 except KeyError:
675 raise JavascriptException(f"Pinned script could not be found: {script_id}") from None
676
677 converted_args = list(args)
678 command = Command.W3C_EXECUTE_SCRIPT
679
680 return self.execute(command, {"script": script, "args": converted_args})["value"]
681
682 def execute_async_script(self, script: str, *args) -> Any:
683 """Asynchronously Executes JavaScript in the current window/frame.

Callers 10

debugMethod · 0.95
submitMethod · 0.45
get_propertyMethod · 0.45
get_attributeMethod · 0.45
is_displayedMethod · 0.45
_w3c_windowMethod · 0.45
_current_contextMethod · 0.45
_classic_snapshotMethod · 0.45
mutation_eventsMethod · 0.45

Calls 2

executeMethod · 0.95
JavascriptExceptionClass · 0.90

Tested by

no test coverage detected