Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an arguments parameter to execute_script #13

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,22 @@ Basically all methods that are part of the `SeElements` object will be automatic

(Look at the code for more detail.)

### Executing JavaScript code

#### Executing code with no arguments

```python
se.execute_script(script="alert('Executing some JS code')", ttl=10)
```

#### Execute Javascript code on a specific element
```python
# Draw a border around an element to highlight it
input_field = se.find("input")
script = "arguments[0].style.border='5px solid #6bf442'"
# input_field is a collection of elements so you need to get the first one
se.execute_script(script=script, arguments=input_field.item, ttl=10)
```

### Making assertions

Expand Down
5 changes: 3 additions & 2 deletions elementium/drivers/se.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,11 @@ def current_url(self):
return self.browser.current_url

def execute_script(
self, script, callback=None, asynchronous=False, ttl=None):
self, script, arguments = None, callback=None, asynchronous=False, ttl=None):
"""Execute arbitrary JavaScript

:param script: The JavaScript to execute
:param arguments: Arguments to be passed to the script
:param callback: A function to execute with the results of the script.
This function should take a single parameter, the
results from the script.
Expand All @@ -553,7 +554,7 @@ def execute_script(
raise NotImplementedError(
"Can't perform asynchronous scripts yet. Sorry.")
results = self.retried(
lambda: self.browser.execute_script(script), update=False)
lambda: self.browser.execute_script(script, arguments), update=False)
if not callback:
return results
else:
Expand Down