Robot Framework SeleniumLibrary
SeleniumLibrary.keywords.javascript.JavaScriptKeywords Class Reference
Inheritance diagram for SeleniumLibrary.keywords.javascript.JavaScriptKeywords:
SeleniumLibrary.base.librarycomponent.LibraryComponent SeleniumLibrary.base.context.ContextAware

Public Member Functions

def execute_async_javascript (self, *code)
 Executes asynchronous JavaScript code with possible arguments. More...
 
def execute_javascript (self, *code)
 Executes the given JavaScript code with possible arguments. More...
 
- Public Member Functions inherited from SeleniumLibrary.base.librarycomponent.LibraryComponent
def assert_page_contains (self, locator, tag=None, message=None, loglevel='TRACE')
 
def assert_page_not_contains (self, locator, tag=None, message=None, loglevel='TRACE')
 
def debug (self, msg, html=False)
 
def get_timeout (self, timeout=None)
 
def info (self, msg, html=False)
 
def log (self, msg, level='INFO', html=False)
 
def log_source (self, loglevel='INFO')
 
def warn (self, msg, html=False)
 
- Public Member Functions inherited from SeleniumLibrary.base.context.ContextAware
def __init__ (self, ctx)
 Base class exposing attributes from the common context. More...
 
def find_element (self, locator, tag=None, required=True, parent=None)
 Find element matching locator. More...
 
def find_elements (self, locator, tag=None, parent=None)
 Find all elements matching locator. More...
 
def is_element_enabled (self, locator, tag=None)
 
def is_text_present (self, text)
 
def is_visible (self, locator)
 

Static Public Attributes

string arg_marker = 'ARGUMENTS'
 
string js_marker = 'JAVASCRIPT'
 

Private Member Functions

def _check_marker_error (self, code)
 
def _get_javascript_to_execute (self, code)
 
def _get_marker_index (self, code)
 
def _js_logger (self, base, code, args)
 
def _read_javascript_from_file (self, path)
 
def _separate_code_and_args (self, code)
 

Additional Inherited Members

- Public Attributes inherited from SeleniumLibrary.base.context.ContextAware
 ctx
 
- Properties inherited from SeleniumLibrary.base.librarycomponent.LibraryComponent
 log_dir = property
 
- Properties inherited from SeleniumLibrary.base.context.ContextAware
 driver = property
 
 drivers = property
 
 element_finder = property
 

Detailed Description

Definition at line 25 of file javascript.py.

Member Function Documentation

◆ _check_marker_error()

def SeleniumLibrary.keywords.javascript.JavaScriptKeywords._check_marker_error (   self,
  code 
)
private

Definition at line 136 of file javascript.py.

◆ _get_javascript_to_execute()

def SeleniumLibrary.keywords.javascript.JavaScriptKeywords._get_javascript_to_execute (   self,
  code 
)
private

Definition at line 112 of file javascript.py.

◆ _get_marker_index()

def SeleniumLibrary.keywords.javascript.JavaScriptKeywords._get_marker_index (   self,
  code 
)
private

Definition at line 151 of file javascript.py.

◆ _js_logger()

def SeleniumLibrary.keywords.javascript.JavaScriptKeywords._js_logger (   self,
  base,
  code,
  args 
)
private

Definition at line 103 of file javascript.py.

◆ _read_javascript_from_file()

def SeleniumLibrary.keywords.javascript.JavaScriptKeywords._read_javascript_from_file (   self,
  path 
)
private

Definition at line 163 of file javascript.py.

◆ _separate_code_and_args()

def SeleniumLibrary.keywords.javascript.JavaScriptKeywords._separate_code_and_args (   self,
  code 
)
private

Definition at line 122 of file javascript.py.

◆ execute_async_javascript()

def SeleniumLibrary.keywords.javascript.JavaScriptKeywords.execute_async_javascript (   self,
code 
)

Executes asynchronous JavaScript code with possible arguments.

    Similar to `Execute Javascript` except that scripts executed with
    this keyword must explicitly signal they are finished by invoking the
    provided callback. This callback is always injected into the executed
    function as the last argument.

    Scripts must complete within the script timeout or this keyword will
    fail. See the `Timeout` section for more information.

    Starting from SeleniumLibrary 3.2 it is possible to provide JavaScript
    [https://seleniumhq.github.io/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html#selenium.webdriver.remote.webdriver.WebDriver.execute_async_script|
    arguments] as part of ``code`` argument. See `Execute Javascript` for
    more details.

    Examples:
    | `Execute Async JavaScript` | var callback = arguments[arguments.length - 1]; window.setTimeout(callback, 2000); |
    | `Execute Async JavaScript` | ${CURDIR}/async_js_to_execute.js |
    | ${result} = | `Execute Async JavaScript`                      |
    | ...         | var callback = arguments[arguments.length - 1]; |
    | ...         | function answer(){callback("text");};           |
    | ...         | window.setTimeout(answer, 2000);                |
    | `Should Be Equal` | ${result} | text |

Definition at line 98 of file javascript.py.

◆ execute_javascript()

def SeleniumLibrary.keywords.javascript.JavaScriptKeywords.execute_javascript (   self,
code 
)

Executes the given JavaScript code with possible arguments.

    ``code`` may be divided into multiple cells in the test data and
    ``code`` may contain multiple lines of code and arguments. In that case,
    the JavaScript code parts are concatenated together without adding
    spaces and optional arguments are separated from ``code``.

    If ``code`` is a path to an existing file, the JavaScript
    to execute will be read from that file. Forward slashes work as
    a path separator on all operating systems.

    The JavaScript executes in the context of the currently selected
    frame or window as the body of an anonymous function. Use ``window``
    to refer to the window of your application and ``document`` to refer
    to the document object of the current frame or window, e.g.
    ``document.getElementById('example')``.

    This keyword returns whatever the executed JavaScript code returns.
    Return values are converted to the appropriate Python types.

    Starting from SeleniumLibrary 3.2 it is possible to provide JavaScript
    [https://seleniumhq.github.io/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html#selenium.webdriver.remote.webdriver.WebDriver.execute_script|
    arguments] as part of ``code`` argument. The JavaScript code and
    arguments must be separated with `JAVASCRIPT` and `ARGUMENTS` markers
    and must used exactly with this format. If the Javascript code is
    first, then the `JAVASCRIPT` marker is optional. The order of
    `JAVASCRIPT` and `ARGUMENTS` markers can swapped, but if `ARGUMENTS`
    is first marker, then `JAVASCRIPT` marker is mandatory. It is only
    allowed to use `JAVASCRIPT` and `ARGUMENTS` markers only one time in the
    ``code`` argument.

    Examples:
    | `Execute JavaScript` | window.myFunc('arg1', 'arg2') |
    | `Execute JavaScript` | ${CURDIR}/js_to_execute.js    |
    | `Execute JavaScript` | alert(arguments[0]); | ARGUMENTS | 123 |
    | `Execute JavaScript` | ARGUMENTS | 123 | JAVASCRIPT | alert(arguments[0]); |

Definition at line 68 of file javascript.py.

Member Data Documentation

◆ arg_marker

string SeleniumLibrary.keywords.javascript.JavaScriptKeywords.arg_marker = 'ARGUMENTS'
static

Definition at line 28 of file javascript.py.

◆ js_marker

string SeleniumLibrary.keywords.javascript.JavaScriptKeywords.js_marker = 'JAVASCRIPT'
static

Definition at line 27 of file javascript.py.


The documentation for this class was generated from the following file: