How to find an item having same id by index from a list view - kotlin

In XCTest, we could find a specific UI element by index, for instance, a list view has reused item with same identifier.
app.staticTexts.matching(identifier: "BETTER").element(boundBy: 1)
So, do we have an alternative method to find an element from a list view for Android UIautomator. I found this one could get element by id, but seems it only returns the first match.
mDevice.findObject(UiSelector().resourceId("id"))

Related

How to find all visible deeply nested ListView items?

Im working on a squish based test and try to get decent (visible) items from a QML ListView that are deeply nested that i just can't pick due to its dynamic behavior
I've get the list itself by using waitForObject with a object map name
There are several nested items in the list an i want to get all occurrences of the MyTypeCCC_QMLTYPE_72 when property visible is true
I've dumped my current class/property child-hierachy:
MyTypeAAA_QMLTYPE_195
children[0] QQuickItem
children[0] QQuickColumn
children[0] MyTypeBBB_QMLTYPE_189
children[0] MyTypeCCC_QMLTYPE_7 visible(true)
I've found this in the Squish-KB: https://kb.froglogic.com/display/KB/Example+-+Finding+child+objects+by+type+and+property+values
so i can write my own search code traversing the tree etc. but i think that could(should) be an easier solution?
can i rely on the exact hierarchy? (but what i the UI design changed another time)
i could maybe add ids to the MyTypeCCC_... if that helps
I've got several of this list with different types/nesting and i hope to find a easy solution that works for all/many of the case
any ideas?
ListView is a subclass of Flickable and all its delegates are immediate children of ContentItem, you can safely iterate over its children to get all list items, but be aware that not all of its children are list delegates, so you have to filter them, e.g. by type. To find nested elements just search for them inside list item, i.e. use list item as a container. To create container locator you can use its coordinates (these are coordinates within the list, so they will be unique). Code may look like this:
list_view = findObject(list_locator)
nested = []
for i in range(list_view.contentItem.children.count):
item = list_view.contentItem.children.at(i)
if className(item) == 'MyTypeAAA':
netsed.append(findObject({'container': {'x': item.x, 'y': item.y, 'type': className(item)}, 'type': 'MyTypeCCC'}))

Get last element from several results with cssselector

So I have this CSS-selector query that returns several results:
div[class=b-folders] span[class=b-folders__folder]
And I want to get only the last one, I tried;
div[class=b-folders] span[class=b-folders__folder]:last-of-type
But nothing was found.
:last-of-type, :last-child and other relevant pseudo-classes/selectors check the element's position inside it's parent:
The :last-of-type CSS pseudo-class represents the last sibling with the given element name in the list of children of its parent element.
Instead, solve it using your selenium language bindings - get all elements matching the selector and get the last found element. For instance, in Python:
driver.find_elements_by_css_selector("div[class=b-folders] span[class=b-folders__folder]")[-1]
You can have an array list of elements and then select the last element by:
List<WebElement> elements= driver.findElements(By.css("css"));
element = elements.get(list.size() - 1);

How can I have multiple instances of same dojo form element with same id in a page?

I have a page say profile.htm with dojo declarative form with id="myForm". I have another page say dashboard.htm having border layout with 3 content pane. I want to show the profile.htm in all these three contentPanes. But when I try this then it gives registration error because there will be three forms with same Id.
Is there any solution for this so that I can have same page (with same id) in many contentPanes?
You simply can't, it's because of the HTML spec:
The id global attribute defines a unique identifier (ID) which must be unique in the whole document.
See: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id
The same goes for dijit's, if there are many dijit's with the ID myDijit what would registry.byId('myDijit') return? Dijit has it's own method of assigning unique ID's just as long as you don't assign one.

how to get child properties of the div object for rational functinal tester

in my application i have a dropdown which is div object.the dropdown contain names and checkboxes.i need select the checkbox based on name. checkbox dont have any name.just index.can any one suggest how to get chaild items or properties of the objects for div object.
and the second question is i have tree view .which is teleric object.RFT is unable to find the object.it identifying as one all tree view is one object.its not identifying the childs,sub tree items....
so please help me on this two issues.
Hi you can get the checkboxes as follows:
void getCheckBoxes(TestObject parentDiv)
{
TestObject[] checkboxes = parentDiv.find(atDescendant(".class","Html.INPUT.checkbox"));
System.out.println("Found " + checkboxes.length);
//Go through them , and decide which one to select.
for(TestObject checkbox: checkboxes)
{
System.out.println("Checkbox Value: "+ checkbox.getProperty(".value"));
}
}
you can call the above method and pass it the parent DIV object.
About the second question:
You have not mentioed how does RFT recognize the one object for the tree ( means which proxy does it use as per the object map's adminitrative properties for that object).
Usually controls like tree /grid etc are recognized as one control and the items of these controls as "Subitem" which are found by specifying subitem as atPath("xyz->abc") etc.

Sencha Touch 2: Give a different itemTpl to nested list leaf nodes

In my nested list I have 2 levels. Currently it shows a standard list. When you click an item it takes you to a list of that item's children. Those children are the leaf nodes. So when you tap one of those it takes you to the detail card for that item. I'd like to use a different list item template for the children than the parent items. Is there a way to use Ext.XTemplate to check if an item is a leaf node or not?
Figured it out:
Simply update the x-list-item-leaf class
.x-list-item-leaf{
color:red !important;
}