Element Lists
When a selector
includes "returnAll": true
, the generated method returns a list.
In the DOM, a parent can contain multiple instances of a custom element, like lightning-tab
components inside a lightning-tabset
. If the selector
has a returnAll
property set to true
, the method returns a list of instances found at run time.
{
"elements": [
{
"name": "allTabs",
"type": "utam-lightning/pageObjects/lightning/tab",
"selector": {
"css": "lightning-tab",
"returnAll": true
},
"public": true
}
]
}
From the previous JSON, UTAM generates this public method, which returns a list of the page objects of the given type.
public List<Tab> getAllTabs() {
// return list of instances found in runtime
// throw exception if nothing found
}
Indexes
To get one of the instances by its index, add :nth-of-type(%d)
to the injected selector and the args
property with an index
parameter. :nth-of-type(%d)
is 1-based, not 0-based.
{
"elements": [
{
"name": "myComponent",
"type": "utam-lightning/pageObjects/lightning/myComponent",
"selector": {
"css": "lightning-my-component:nth-of-type(%d)",
"args": [
{
"name": "index",
"type": "number"
}
]
},
"public": true
}
]
}
The generated method finds all the custom elements inside the parent and returns one by index
.
public MyComponent getMyComponent(int index) {
// return nth instance
// if nothing found, or index is out of bounds, throw exception
}