Skip to content

Commit 02beb60

Browse files
author
Adrian Tamas
committed
add an arguments parameter to execute_script
remove version bump
1 parent 378c38e commit 02beb60

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,22 @@ Basically all methods that are part of the `SeElements` object will be automatic
290290

291291
(Look at the code for more detail.)
292292

293+
### Executing JavaScript code
294+
295+
#### Executing code with no arguments
296+
297+
```python
298+
se.execute_script(script="alert('Executing some JS code')", ttl=10)
299+
```
300+
301+
#### Execute Javascript code on a specific element
302+
```python
303+
# Draw a border around an element to highlight it
304+
input_field = se.find("input")
305+
script = "arguments[0].style.border='5px solid #6bf442'"
306+
# input_field is a collection of elements so you need to get the first one
307+
se.execute_script(script=script, arguments=input_field.item, ttl=10)
308+
```
293309

294310
### Making assertions
295311

elementium/drivers/se.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,11 @@ def current_url(self):
536536
return self.browser.current_url
537537

538538
def execute_script(
539-
self, script, callback=None, asynchronous=False, ttl=None):
539+
self, script, arguments = None, callback=None, asynchronous=False, ttl=None):
540540
"""Execute arbitrary JavaScript
541541
542542
:param script: The JavaScript to execute
543+
:param arguments: Arguments to be passed to the script
543544
:param callback: A function to execute with the results of the script.
544545
This function should take a single parameter, the
545546
results from the script.
@@ -553,7 +554,7 @@ def execute_script(
553554
raise NotImplementedError(
554555
"Can't perform asynchronous scripts yet. Sorry.")
555556
results = self.retried(
556-
lambda: self.browser.execute_script(script), update=False)
557+
lambda: self.browser.execute_script(script, arguments), update=False)
557558
if not callback:
558559
return results
559560
else:

0 commit comments

Comments
 (0)