<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Squish for Java, select an item in a list box]]></title><description><![CDATA[<p dir="auto">I use Squish for Java (on a JavaFX app)  and need to select an item in a list/combobox.<br />
I don't know upfront (design-time) which item I need to select as it is an input to my test.<br />
When the item is visible in the list when the list opens, my code works.<br />
But when the item is not visible (yet) and you would have to scroll down in the list, my code does not work.<br />
Any suggestions on how to solve this in a generic way (so with items visible by default and not visible by default) ?</p>
]]></description><link>https://forum.qt.io/topic/163979/squish-for-java-select-an-item-in-a-list-box</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 18:35:04 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/163979.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 23 Dec 2025 10:12:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Squish for Java, select an item in a list box on Tue, 01 Sep 2026 18:54:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/emma-2000">@<bdi>Emma-2000</bdi></a> said in <a href="/post/839633">Squish for Java, select an item in a list box</a>:</p>
<blockquote>
<p dir="auto">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.</p>
</blockquote>
<p dir="auto">Agreed on using the model and toolkit API to access or even scroll a particular object into view.</p>
<p dir="auto">(Squish for Java tries to automatically scroll an object into view upon mouseClick(). And one can pass <code>Button.NoButton</code> (<a href="https://doc.qt.io/squish/java-convenience-api.html#java-convenience-function-parameters" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/squish/java-convenience-api.html#java-convenience-function-parameters</a>) to <code>mouseClick()</code> to trigger the scrolling attempt without performing a mouse click.)</p>
<blockquote>
<p dir="auto">The approach with <code>obj.items.length</code>, <code>obj.items.get(i)</code> and assigning <code>obj.value</code> looks particularly useful for making the test independent of the item’s position in the list.</p>
</blockquote>
<p dir="auto"><code>obj.items.get(i)</code> requires specifying the index of the item, which I intuitively understand to be the "position in the list".</p>
<p dir="auto">Perhaps by "position" you meant the location on the screen? If so, yes, hardcoded positions are better to be avoided. (Squish <strong>is</strong> 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.</p>
]]></description><link>https://forum.qt.io/post/839935</link><guid isPermaLink="true">https://forum.qt.io/post/839935</guid><dc:creator><![CDATA[clanhuth]]></dc:creator><pubDate>Tue, 01 Sep 2026 18:54:47 GMT</pubDate></item><item><title><![CDATA[Reply to Squish for Java, select an item in a list box on Mon, 14 Sep 2026 11:13:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/henry.ishiyama">@<bdi>henry.ishiyama</bdi></a> said in <a href="/post/835186">Squish for Java, select an item in a list box</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pieter-knelissen">@<bdi>Pieter-Knelissen</bdi></a> sorry for the delay.<br />
regarding the attributes/methos available, it depends on the UI component used and the UI structure.<br />
For example in our above sample test case "tmpObj" for the given sample application,<br />
After the test case hits the breakpoint, and see the "Variables View", you will see "type" of each local variable.<br />
And the "type" for "tmpObj" is javax_swing_JList. (Attached screenshot)<br />
Therefore, from there on, you have to look into the JList and related UI component documentation to access the desired attributes and methods.<br />
<img src="https://ddgobkiprc33d.cloudfront.net/9366681d-0b7c-4dfa-93c8-2f3cb6c22144.png" alt="image.png" class=" img-fluid img-markdown" /></p>
</blockquote>
<p dir="auto">Just to add, and visible in the screenshot as well: The object's (fully qualified) class name can be seen in the view "Application Objects" as well.</p>
<p dir="auto">Alternatives to the use of the API documentation of the individual types/classes of GUI objects can be:</p>
<ul>
<li>
<p dir="auto">On object references: Use Python's dir() function. This will list all members, including methods.</p>
</li>
<li>
<p dir="auto">When the object can be picked: You can see the member variables in Squish IDE's "Properties" view, and the methods in the "Methods" view.</p>
</li>
</ul>
<p dir="auto">There is one Squish specialty here:</p>
<p dir="auto">Squish for Java maps getter/setter pairs to pseudo member variables. For example:</p>
<p dir="auto">If the object's class has...</p>
<pre><code>getThisOneThing()
setThisOneThing()
</code></pre>
<p dir="auto">...then Squish makes the pseudo member variable...</p>
<pre><code>thisonething
</code></pre>
<p dir="auto">...(yes, all lowercase) available on the object reference.</p>
]]></description><link>https://forum.qt.io/post/839934</link><guid isPermaLink="true">https://forum.qt.io/post/839934</guid><dc:creator><![CDATA[clanhuth]]></dc:creator><pubDate>Mon, 14 Sep 2026 11:13:14 GMT</pubDate></item><item><title><![CDATA[Reply to Squish for Java, select an item in a list box on Mon, 10 Aug 2026 13:11:06 GMT]]></title><description><![CDATA[<p dir="auto">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.</p>
<p dir="auto">The approach with <code>obj.items.length</code>, <code>obj.items.get(i)</code> and assigning <code>obj.value</code> looks particularly useful for making the test independent of the item’s position in the list.</p>
]]></description><link>https://forum.qt.io/post/839633</link><guid isPermaLink="true">https://forum.qt.io/post/839633</guid><dc:creator><![CDATA[Emma-2000]]></dc:creator><pubDate>Mon, 10 Aug 2026 13:11:06 GMT</pubDate></item><item><title><![CDATA[Reply to Squish for Java, select an item in a list box on Mon, 05 Jan 2026 00:35:32 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pieter-knelissen">@<bdi>Pieter-Knelissen</bdi></a> sorry for the delay.<br />
regarding the attributes/methos available, it depends on the UI component used and the UI structure.<br />
For example in our above sample test case "tmpObj" for the given sample application,<br />
After the test case hits the breakpoint, and see the "Variables View", you will see "type" of each local variable.<br />
And the "type" for "tmpObj" is javax_swing_JList. (Attached screenshot)<br />
Therefore, from there on, you have to look into the JList and related UI component documentation to access the desired attributes and methods.<br />
<img src="https://ddgobkiprc33d.cloudfront.net/9366681d-0b7c-4dfa-93c8-2f3cb6c22144.png" alt="image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/835186</link><guid isPermaLink="true">https://forum.qt.io/post/835186</guid><dc:creator><![CDATA[henry.ishiyama]]></dc:creator><pubDate>Mon, 05 Jan 2026 00:35:32 GMT</pubDate></item><item><title><![CDATA[Reply to Squish for Java, select an item in a list box on Wed, 31 Dec 2025 14:06:52 GMT]]></title><description><![CDATA[<p dir="auto">I don't have the Java-code of the app that I need to run/test. What worked for me:<br />
obj = waitForObject (&lt;name of the combobox&gt;)<br />
obj.items.length gives the number of items in the combobox<br />
with obj.items.get(i) I retrieve the value of an item<br />
with obj.value=&lt;value to assign&gt; I assign the value as if I had clicked it.</p>
]]></description><link>https://forum.qt.io/post/835065</link><guid isPermaLink="true">https://forum.qt.io/post/835065</guid><dc:creator><![CDATA[Pieter Knelissen]]></dc:creator><pubDate>Wed, 31 Dec 2025 14:06:52 GMT</pubDate></item><item><title><![CDATA[Reply to Squish for Java, select an item in a list box on Tue, 30 Dec 2025 12:43:25 GMT]]></title><description><![CDATA[<p dir="auto">Henry, an additional question if I may:<br />
where can I find the attributes/methods supported by the various 'objects' that you mention in the python code?<br />
E.g. tmpObj.parent.view.getModel() : how do I know that 'parent', 'view' and 'getModel()' exist for the tmpObj?</p>
]]></description><link>https://forum.qt.io/post/835006</link><guid isPermaLink="true">https://forum.qt.io/post/835006</guid><dc:creator><![CDATA[Pieter Knelissen]]></dc:creator><pubDate>Tue, 30 Dec 2025 12:43:25 GMT</pubDate></item><item><title><![CDATA[Reply to Squish for Java, select an item in a list box on Mon, 29 Dec 2025 14:29:54 GMT]]></title><description><![CDATA[<p dir="auto">Henry, thank you for the pointers!</p>
]]></description><link>https://forum.qt.io/post/834966</link><guid isPermaLink="true">https://forum.qt.io/post/834966</guid><dc:creator><![CDATA[Pieter Knelissen]]></dc:creator><pubDate>Mon, 29 Dec 2025 14:29:54 GMT</pubDate></item><item><title><![CDATA[Reply to Squish for Java, select an item in a list box on Thu, 25 Dec 2025 05:45:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pieter-knelissen">@<bdi>Pieter-Knelissen</bdi></a><br />
It is possible to use the following functions to scroll to the desired item.<br />
"<a href="https://doc.qt.io/squish/java-setvalue-function.html" target="_blank" rel="noopener noreferrer nofollow ugc">setValue</a> ", "<a href="https://doc.qt.io/squish/java-mousewheel-function.html" target="_blank" rel="noopener noreferrer nofollow ugc">mouseWheel</a>"</p>
<p dir="auto">Also you can dump the complete List into a variable and access it.</p>
<p dir="auto">For example as follows:</p>
<h6>**sample test case : **</h6>
<pre><code># -*- coding: utf-8 -*-

import names


def main():
    startApplication("run.bat")
    
    # Use "setValue" and "mouseWheel" functions to scroll
    mouseClick(waitForObjectItem(names.defaultListModel_Example_JList, "Banana"), 75, 14, 0, Button.Button1)
    mouseClick(waitForObjectItem(names.defaultListModel_Example_JList, "Pineapple"), 77, 3, 0, Button.Button1)
    setValue(waitForObject(names.defaultListModel_Example_JScrollBar), 504) # setValue -&gt; https://doc.qt.io/squish/java-setvalue-function.html
    setValue(waitForObject(names.defaultListModel_Example_JScrollBar), 378) # setValue -&gt; https://doc.qt.io/squish/java-setvalue-function.html
    setValue(waitForObject(names.defaultListModel_Example_JScrollBar), 630) # setValue -&gt; https://doc.qt.io/squish/java-setvalue-function.html
    setValue(waitForObject(names.defaultListModel_Example_JScrollBar), 74) # setValue -&gt; https://doc.qt.io/squish/java-setvalue-function.html
    mouseClick(waitForObjectItem(names.defaultListModel_Example_JList, "Raspberry"), 241, 5, 0, Button.Button1)
    setValue(waitForObject(names.defaultListModel_Example_JScrollBar), 189) # setValue -&gt; https://doc.qt.io/squish/java-setvalue-function.html
    mouseClick(waitForObjectItem(names.defaultListModel_Example_JList, "Nectarine"), 190, 7, 0, Button.Button1)
    
    j = 1
    for i in range(0, 25):
        j = (j * -1)
        mouseWheel((i * j)) # mouseWheel -&gt; https://doc.qt.io/squish/java-mousewheel-function.html
        snooze(1)

    # Dump the complete List into a variable and access it.
    tmpObj = waitForObject(names.defaultListModel_Example_JList)
    tmpList = tmpObj.parent.view.getModel()
    tmpSize = tmpList.size
    
    for i in range(0, tmpSize):
        tmpItem = tmpList.get(i)
        test.log(f"{i} {tmpItem}")

    test.breakpoint()
</code></pre>
<h6>**sample application : **</h6>
<pre><code>// Example: Basic Usage
import javax.swing.*;
import java.awt.*;

public class ListExample {
    public static void main(String[] args) {
        JFrame frame = new JFrame("DefaultListModel Example");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300, 200);

        // 1. Create the model
        DefaultListModel&lt;String&gt; listModel = new DefaultListModel&lt;&gt;();

        // 2. Add data to the model
        listModel.addElement("Apple");
        listModel.addElement("Banana");
        listModel.add(1, "Orange"); // Insert Orange at index 1
        listModel.addElement("Mango");
        listModel.addElement("Pineapple");
        listModel.addElement("Grapes");
        listModel.addElement("Strawberry");
        listModel.addElement("Blueberry");
        listModel.addElement("Raspberry");
        listModel.addElement("Blackberry");
        listModel.addElement("Cherry");
        listModel.addElement("Peach");
        listModel.addElement("Plum");
        listModel.addElement("Apricot");
        listModel.addElement("Nectarine");
        listModel.addElement("Kiwi");
        listModel.addElement("Papaya");
        listModel.addElement("Guava");
        listModel.addElement("Lychee");
        listModel.addElement("Dragon fruit");
        listModel.addElement("Passion fruit");
        listModel.addElement("Pomegranate");
        listModel.addElement("Watermelon");
        listModel.addElement("Cantaloupe");
        listModel.addElement("Honeydew melon");
        listModel.addElement("Coconut");
        listModel.addElement("Fig");
        listModel.addElement("Date");
        listModel.addElement("Persimmon");
        listModel.addElement("Cranberry");
        listModel.addElement("Mulberry");
        listModel.addElement("Gooseberry");
        listModel.addElement("Starfruit (Carambola)");
        listModel.addElement("Jackfruit");
        listModel.addElement("Durian");
        listModel.addElement("Tamarind");
        listModel.addElement("Olive");
        listModel.addElement("Avocado");
        listModel.addElement("Lemon");
        listModel.addElement("Lime");
        listModel.addElement("Grapefruit");
        listModel.addElement("Tangerine");
        listModel.addElement("Clementine");
        listModel.addElement("Soursop");
        listModel.addElement("Sapodilla");
        listModel.addElement("Rambutan");
        listModel.addElement("Longan");
        listModel.addElement("Mangosteen");
        listModel.addElement("Breadfruit");
        listModel.addElement("Custard apple");

        // 3. Create JList with the model
        JList&lt;String&gt; fruitList = new JList&lt;&gt;(listModel);
        fruitList.setFont(new Font("Arial", Font.PLAIN, 16));

        // Add list to a scroll pane for better viewing
        JScrollPane scrollPane = new JScrollPane(fruitList);
        frame.add(scrollPane, BorderLayout.CENTER);

        frame.setVisible(true);
    }
}
</code></pre>
]]></description><link>https://forum.qt.io/post/834874</link><guid isPermaLink="true">https://forum.qt.io/post/834874</guid><dc:creator><![CDATA[henry.ishiyama]]></dc:creator><pubDate>Thu, 25 Dec 2025 05:45:16 GMT</pubDate></item><item><title><![CDATA[Reply to Squish for Java, select an item in a list box on Wed, 24 Dec 2025 16:37:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/henry.ishiyama">@<bdi>henry.ishiyama</bdi></a> : Indeed. The list (from the list/combo box) from which I have to select is pretty long and by default only part of the list is visible. It requires scrolling in the list to make other items visible.<br />
But design-time, I don't know how much I have to scroll to make the desired item (the item to select) visible.<br />
The silly way that I found is to squish.NativeType("&lt;Down&gt;") and inspect the value of the 'current' item until I have found my desired item.<br />
There must be some smarter way....</p>
]]></description><link>https://forum.qt.io/post/834868</link><guid isPermaLink="true">https://forum.qt.io/post/834868</guid><dc:creator><![CDATA[Pieter Knelissen]]></dc:creator><pubDate>Wed, 24 Dec 2025 16:37:21 GMT</pubDate></item><item><title><![CDATA[Reply to Squish for Java, select an item in a list box on Wed, 24 Dec 2025 00:20:34 GMT]]></title><description><![CDATA[<p dir="auto">To interact with UI component (ex: list item),  it has to exist, is visible and enabled.</p>
]]></description><link>https://forum.qt.io/post/834860</link><guid isPermaLink="true">https://forum.qt.io/post/834860</guid><dc:creator><![CDATA[henry.ishiyama]]></dc:creator><pubDate>Wed, 24 Dec 2025 00:20:34 GMT</pubDate></item></channel></rss>