How to click a Button with ImageView in a TableView

435 views
Skip to first unread message

Tommy Yeh

unread,
Mar 28, 2016, 11:37:05 PM3/28/16
to TestFX
Could someone give me some example ?

How to click a Button with ImageView in a TableView?

Thanks a lot !!!

Benjamin Gudehus

unread,
Mar 29, 2016, 2:46:37 AM3/29/16
to Tommy Yeh, TestFX
Hey Tommy,

if the `Button` has graphics instead of (unique) text you need another way to query it.

The easiest way is to set the `Button`'s id and use `clickOn("#id")`, where "id" is the id you use.

Another way is to query the table cell (in which the button is) first and then to query `.button`, iff the table cell contains only a single button.

Here is a code example (for TestFX 4.0.3-alpha). "#myTableView" is the id of your `TableView`, rowIndex the table row index and columnIndex the table column index.

~~~java
clickOn(lookup("#myTableView")
    .lookup(".table-row-cell").nth(rowIndex)
    .lookup(".table-cell").nth(columnIndex)
    .lookup(".button").query())
~~~

--Benjamin

--
You received this message because you are subscribed to the Google Groups "TestFX" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testfx-discus...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tommy Yeh

unread,
Mar 30, 2016, 2:22:09 AM3/30/16
to TestFX
Thank you Benjamin.

You do me a big favor !

Tommy Yeh

unread,
Mar 30, 2016, 4:12:49 AM3/30/16
to TestFX
Hey Benjamin,

Can I ask one more question ?

if I have a TabPane and got some Tabs with id in it,

How can I use robot to close the specific tab ?

Benjamin Gudehus

unread,
Mar 30, 2016, 5:37:43 AM3/30/16
to Tommy Yeh, TestFX
This should be similar to the TableView+Button case.

A ".tab-pane" has ".tab"s, which have a ".tab-close-button" (in case the tab closing policy property has the appropriate value set).

So the previous example:

~~~java
clickOn(lookup("#myTableView")
    .lookup(".table-row-cell").nth(rowIndex)
    .lookup(".table-cell").nth(columnIndex)
    .lookup(".button").query())
~~~

can be changed to :

~~~java
clickOn(lookup("#myTabPane")
    .lookup(".tab").nth(tabIndex)
    .lookup(".tab-close-button").query())
~~~

I haven't tested it, but this should give a hint for a solution.

Also: SceneBuilder [1] allows to inspect the CSS properties of JavaFX controls (using the menu entry View > Show CSS Analyzer). On the right side of the toolbar of the CSS Analyzer panel there are two cursor tools (CSS Selection Mode and CSS Picking Mode). The CSS picking mode (activated by default after the panel was opened) allows to select parts of the JavaFX controls' skins and inspect their CSS properties.


--Benjamin







--

Tommy Yeh

unread,
Mar 30, 2016, 9:57:33 PM3/30/16
to TestFX
Thank you very much Benjamin !


burcu yapıcı

unread,
Oct 20, 2017, 3:52:24 AM10/20/17
to TestFX



Hi Benjamin I try your code for tableview imageView button but it gives this error. I couldn't solve. Do you have any idea for this?

Regards... 

burcu yapıcı

unread,
Oct 20, 2017, 3:53:55 AM10/20/17
to TestFX
I try with clikOn but I gave same error.

20 Ekim 2017 Cuma 10:52:24 UTC+3 tarihinde burcu yapıcı yazdı:
Reply all
Reply to author
Forward
0 new messages