Typically, you would use the provided high-level element API to interact with components. For situations in which a high-level API isn’t available or doesn’t offer the methods you need, a few helpers are provided.
Many interactions with web components can be performed by reading or modifying element properties. For this, the following helpers are provided in
String getPropertyString(String... propertyNames) Boolean getPropertyBoolean(String... propertyNames) Integer getPropertyInteger(String... propertyNames) Double getPropertyDouble(String... propertyNames) Object getProperty(String... propertyNames) TestBenchElement getPropertyElement(String... propertyNames) List<TestBenchElement> getPropertyElements(String... propertyNames)
These methods are typically meant for creating page objects or TestBench elements, but can also be handy as a workaround when a needed method isn’t available.
Typically, you should use the correct
If you need to call a function on an element, you can use
Object callFunction(String methodName, Object… args), available in
Below is an example of this:
divElement.callFunction("setAttribute", "title", "Hello");
executeScript() method available in
TestBenchElement and add references to elements and other parameters using the
Object… args parameter. All arguments passed to the method are available through the
For example, to return the
offsetHeight property of an element, you could do this:
TestBenchElement element = ...; // find the element somehow Long offsetHeight = (Long)executeScript("return arguments.offsetHeight", element);
The above |
The argument array and the return type support a limited set of types:
HTML elements are converted to
Decimal numbers are converted to
Non-decimal numbers are converted to
Booleans are converted to
All other values except arrays are converted to
Returned arrays are converted to
List<Object>, containing types described above.