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

Method execute_script

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

577 return list(self.pinned_scripts)
578
579 def execute_script(self, script: str, *args) -> Any:
580 """Synchronously Executes JavaScript in the current window/frame.
581
582 Args:
583 script: The javascript to execute.
584 *args: Any applicable arguments for your JavaScript.
585
586 Example:
587 ```
588 id = "username"
589 value = "test_user"
590 driver.execute_script("document.getElementById(arguments[0]).value = arguments[1];", id, value)
591 ```
592 """
593 if isinstance(script, ScriptKey):
594 try:
595 script = self.pinned_scripts[script.id]
596 except KeyError:
597 raise JavascriptException("Pinned script could not be found")
598
599 converted_args = list(args)
600 command = Command.W3C_EXECUTE_SCRIPT
601
602 return self.execute(command, {"script": script, "args": converted_args})["value"]
603
604 def execute_async_script(self, script: str, *args) -> Any:
605 """Asynchronously Executes JavaScript in the current window/frame.

Callers 15

find_elementsMethod · 0.95
debugMethod · 0.95
submitMethod · 0.45
get_propertyMethod · 0.45
get_attributeMethod · 0.45
is_displayedMethod · 0.45
_w3c_windowMethod · 0.45
mutation_eventsMethod · 0.45
get_scroll_topFunction · 0.45

Calls 2

executeMethod · 0.95
JavascriptExceptionClass · 0.90

Tested by 15

get_scroll_topFunction · 0.36
_get_eventsFunction · 0.36
_get_viewport_rectFunction · 0.36
_get_eventsFunction · 0.36
_in_viewportFunction · 0.36