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)
| 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. |