Package de.bmiag.tapir.selenium.js
Class JsExecutor
- java.lang.Object
-
- de.bmiag.tapir.selenium.js.JsExecutor
-
- Direct Known Subclasses:
HtmlUnitJsExecutor
@Component("tapirJsExecutor") public class JsExecutor extends java.lang.Object
TheJsExecutor
provides the methodexecuteJS(String, Object...)
in order to execute JavaScript. It does so by delegating toJavascriptExecutor.executeScript(String, Object...)
.- Since:
- 2.0.0
- Author:
- Oliver Libutzki <[email protected]>
- See Also:
JavascriptExecutor
-
-
Constructor Summary
Constructors Constructor Description JsExecutor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
executeJS(java.lang.String script, java.lang.Object... args)
Executes JavaScript in the context of the currently selected frame or window.boolean
isJavascriptEnabled()
Returns true if Javascript is enabled, otherwise false
-
-
-
Method Detail
-
executeJS
public java.lang.Object executeJS(java.lang.String script, java.lang.Object... args)
Executes JavaScript in the context of the currently selected frame or window. The script fragment provided will be executed as the body of an anonymous function.Within the script, use
document
to refer to the current document. Note that local variables will not be available once the script has finished executing, though global variables will persist.If the script has a return value (i.e. if the script contains a
return
statement), then the following steps will be taken:- For an HTML element, this method returns a WebElement
- For a decimal, a Double is returned
- For a non-decimal number, a Long is returned
- For a boolean, a Boolean is returned
- For all other cases, a String is returned.
- For an array, return a List<Object> with each object following the rules above. We support nested lists.
- Unless the value is null or there is no return value, in which null is returned
Arguments must be a number, a boolean, a String, WebElement, or a List of any combination of the above. An exception will be thrown if the arguments do not meet these criteria. The arguments will be made available to the JavaScript via the "arguments" magic variable, as if the function were called via "Function.apply"
- Parameters:
script
- The JavaScript to executeargs
- The arguments to the script. May be empty- Returns:
- One of Boolean, Long, String, List or WebElement. Or null.
- Throws:
java.lang.UnsupportedOperationException
- thrown if JavaScript is disabled
-
isJavascriptEnabled
public boolean isJavascriptEnabled()
Returns true if Javascript is enabled, otherwise false- Returns:
- true if Javascript is enabled, otherwise false
- Since:
- 2.0.0
-
-