@Emma-2000 said in Squish for Java, select an item in a list box:
I’ve run into a similar issue with long JavaFX lists where the target item isn’t initially visible. Using the component’s available items/model instead of relying only on scrolling seems much more reliable, especially when the test input changes dynamically.
Agreed on using the model and toolkit API to access or even scroll a particular object into view.
(Squish for Java tries to automatically scroll an object into view upon mouseClick(). And one can pass Button.NoButton (https://doc.qt.io/squish/java-convenience-api.html#java-convenience-function-parameters) to mouseClick() to trigger the scrolling attempt without performing a mouse click.)
The approach with obj.items.length, obj.items.get(i) and assigning obj.value looks particularly useful for making the test independent of the item’s position in the list.
obj.items.get(i) requires specifying the index of the item, which I intuitively understand to be the "position in the list".
Perhaps by "position" you meant the location on the screen? If so, yes, hardcoded positions are better to be avoided. (Squish is using screen positions for sending events, etc. - but it determines/calculates these screen locations at runtime.) Ah, after further consideration, you probably meant iterating over the items until the desired one is found. Alright.