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

Method execute_script

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

589 return list(self.pinned_scripts)
590
591 def execute_script(self, script: str, *args) -> Any:
592 """Synchronously Executes JavaScript in the current window/frame.
593
594 Args:
595 script: The javascript to execute.
596 *args: Any applicable arguments for your JavaScript.
597
598 Example:
599 ```
600 id = "username"
601 value = "test_user"
602 driver.execute_script("document.getElementById(arguments[0]).value = arguments[1];", id, value)
603 ```
604 """
605 if isinstance(script, ScriptKey):
606 try:
607 script = self.pinned_scripts[script.id]
608 except KeyError:
609 raise JavascriptException("Pinned script could not be found")
610
611 converted_args = list(args)
612 command = Command.W3C_EXECUTE_SCRIPT
613
614 return self.execute(command, {"script": script, "args": converted_args})["value"]
615
616 def execute_async_script(self, script: str, *args) -> Any:
617 """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