java - TestFX clickOn() 在组合框/选择框上的特定文本上
问题描述
我是使用 fxrobot (javafx) 进行 TestFX GUI 测试的新手。
我当前的任务是在使用组合框创建的下拉菜单上单击一个选项。我没有找到任何提到这个问题的教程。
真的可以实现 clickOn() 方法在组合框/下拉菜单中选择文本吗?有一个例子怎么做吗?
太感谢了!
解决方案
这是用户在给定组合框中选择给定文本的示例。
void user_selects_combo_item(String comboBoxId, String itemToSelect) {
ComboBox<?> actualComboBox = lookupControl(comboBoxId);
// Find and click only on arrow button. This is important for editable combo-boxes.
for (Node child : actualComboBox.getChildrenUnmodifiable()) {
if (child.getStyleClass().contains("arrow-button")) {
Node arrowRegion = ((Pane) child).getChildren().get(0);
robot.clickOn(arrowRegion);
Thread.sleep(100); // try/catch were skipped for shorter code.
robot.clickOn(itemToSelect);
}
}
Assert.fail("Couldn't find an arrow-button.");
}
private <T extends Node> T lookupControl(String controlId) {
T actualControl = robot.lookup(controlId).query();
assertNotNull("Could not find a control by id = " + controlId, actualControl);
return actualControl;
}
推荐阅读
- r - 在因子组中的最小值和最大值之后选择 x 条记录
- php - PHP while 循环处理速度更快,可能使用 PHP 工作者实现
- python - python中sort和sorted之间的区别以及它们的反转?
- c# - 动态 IQueryable 连接查询
- angular - 如何使用 Angular 9 获取窗口登录帐户名?
- python - 是否有一种简单的方法可以在 Python 中为 content-disposition 标头编码(unicode)文件名?
- c# - 如何使用 azure 管道将 .NET Core 应用程序部署到本地文件共享?
- java - protobuf 中具有某些属性的枚举
- sql - 需要基于Condition的SQL查询
- angular - 无法使用角度 7 在表行中动态更改输入数据类型