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