为了账号安全,请及时绑定邮箱和手机立即绑定

TestFX clickOn() 在组合框/选择框上的特定文本上

TestFX clickOn() 在组合框/选择框上的特定文本上

肥皂起泡泡 2022-06-15 15:42:18
我是使用 fxrobot (javafx) 进行 TestFX GUI 测试的新手。我当前的任务是在使用组合框创建的下拉菜单上单击一个选项。我没有找到任何提到这个问题的教程。真的可以实现 clickOn() 方法在组合框/下拉菜单中选择文本吗?有一个例子怎么做吗?太感谢了!
查看完整描述

1 回答

?
喵喵时光机

TA贡献1846条经验 获得超7个赞

这是用户在给定组合框中选择给定文本的示例。


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;

}


查看完整回答
反对 回复 2022-06-15
  • 1 回答
  • 0 关注
  • 94 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号