@@ -68,20 +68,23 @@ def confirm_action(self):
6868 def execute_javascript (self , * code ):
6969 """Executes the given JavaScript code.
7070
71- `code` may contain multiple lines of code but must contain a
72- return statement (with the value to be returned) at the end.
73-
74- `code` may be divided into multiple cells in the test data. In that
75- case, the parts are catenated together without adding spaces.
71+ `code` may contain multiple lines of code and may be divided into
72+ multiple cells in the test data. In that case, the parts are
73+ catenated together without adding spaces.
7674
7775 If `code` is an absolute path to an existing file, the JavaScript
7876 to execute will be read from that file. Forward slashes work as
7977 a path separator on all operating systems.
8078
81- Note that, by default, the code will be executed in the context of the
82- Selenium object itself, so `this` will refer to the Selenium object.
83- Use `window` to refer to the window of your application, e.g.
84- `window.document.getElementById('foo')`.
79+ The JavaScript executes in the context of the currently selected
80+ frame or window. Use _window_ to refer to the window of your
81+ application and _document_ to refer to the document object
82+ of the current frame or window, e.g.
83+ _document.getElementById('foo')_.
84+
85+ This keyword returns None unless there is a return statement in the
86+ JavaScript. Return values are converted to the appropriate type in
87+ Python, including WebElements.
8588
8689 Example:
8790 | Execute JavaScript | window.my_js_function('arg1', 'arg2') |
@@ -94,24 +97,17 @@ def execute_javascript(self, *code):
9497 def execute_async_javascript (self , * code ):
9598 """Executes asynchronous JavaScript code.
9699
97- `code` may contain multiple lines of code but must contain a
98- return statement (with the value to be returned) at the end.
99-
100- `code` may be divided into multiple cells in the test data. In that
101- case, the parts are catenated together without adding spaces.
102-
103- If `code` is an absolute path to an existing file, the JavaScript
104- to execute will be read from that file. Forward slashes work as
105- a path separator on all operating systems.
100+ Similar to `Execute Javascript` except that scripts executed with
101+ this keyword must explicitly signal they are finished by invoking the
102+ provided callback. This callback is always injected into the executed
103+ function as the last argument.
106104
107- Note that, by default, the code will be executed in the context of the
108- Selenium object itself, so `this` will refer to the Selenium object.
109- Use `window` to refer to the window of your application, e.g.
110- `window.document.getElementById('foo')`.
105+ Scripts must complete within the script timeout or this keyword will
106+ fail. See the `Timeouts` section for more information.
111107
112108 Example:
113- | Execute Async JavaScript | window.my_js_function('arg1', 'arg2') |
114- | Execute Async JavaScript | ${CURDIR}/js_to_execute .js |
109+ | Execute Async JavaScript | var callback = arguments[arguments.length - 1]; | window.setTimeout(callback, 2000); |
110+ | Execute Async JavaScript | ${CURDIR}/async_js_to_execute .js | |
115111 """
116112 js = self ._get_javascript_to_execute ('' .join (code ))
117113 self ._info ("Executing Asynchronous JavaScript:\n %s" % js )
0 commit comments