From 02beb6045bad3a87f1001c2ef6652eac011c37d5 Mon Sep 17 00:00:00 2001 From: Adrian Tamas Date: Wed, 7 Aug 2019 13:44:33 +0300 Subject: [PATCH] add an arguments parameter to execute_script remove version bump --- README.md | 16 ++++++++++++++++ elementium/drivers/se.py | 5 +++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3215e3a..b8e9740 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/elementium/drivers/se.py b/elementium/drivers/se.py index cbbfa6a..b43abd9 100644 --- a/elementium/drivers/se.py +++ b/elementium/drivers/se.py @@ -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. @@ -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: