Java combobox/choicebox上特定文本上的TestFX clickOn()

Java combobox/choicebox上特定文本上的TestFX clickOn(),java,javafx,junit,testfx,Java,Javafx,Junit,Testfx,我是使用fxrobot(javafx)测试FXGUI的新手 我当前的任务是单击用combobox创建的下拉菜单上的一个选项。我没有发现任何教程提到这个问题 在组合框/下拉菜单中选择文本是否真的可以实现clickOn()方法?有没有一个例子如何做到这一点 万分感谢 这是用户在给定组合框中选择给定文本的一个示例 void user_selects_combo_item(String comboBoxId, String itemToSelect) { ComboBox<?> ac

我是使用fxrobot(javafx)测试FXGUI的新手

我当前的任务是单击用combobox创建的下拉菜单上的一个选项。我没有发现任何教程提到这个问题

在组合框/下拉菜单中选择文本是否真的可以实现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;
}
void用户\u选择\u组合\u项(String comboBoxId,String itemToSelect){
ComboBox actualComboBox=lookupControl(comboBoxId);
//查找并仅单击箭头按钮。这对于可编辑的组合框很重要。
对于(节点子节点:actualComboBox.getChildrenUnmodifiable()){
if(child.getStyleClass()包含(“箭头按钮”)){
节点arrowRegion=((窗格)child.getChildren().get(0);
机器人。点击(箭头区域);
Thread.sleep(100);//跳过try/catch以获得较短的代码。
robot.点击(项目选择);
}
}
Assert.fail(“找不到箭头按钮”);
}
私有T查找控制(字符串控制ID){
T actualControl=robot.lookup(controlId.query();
assertNotNull(“无法通过id=“+controlId,actualControl”)找到控件;
返回实际控制;
}

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

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;
}
void用户\u选择\u组合\u项(String comboBoxId,String itemToSelect){
ComboBox actualComboBox=lookupControl(comboBoxId);
//查找并仅单击箭头按钮。这对于可编辑的组合框很重要。
对于(节点子节点:actualComboBox.getChildrenUnmodifiable()){
if(child.getStyleClass()包含(“箭头按钮”)){
节点arrowRegion=((窗格)child.getChildren().get(0);
机器人。点击(箭头区域);
Thread.sleep(100);//跳过try/catch以获得较短的代码。
robot.点击(项目选择);
}
}
Assert.fail(“找不到箭头按钮”);
}
私有T查找控制(字符串控制ID){
T actualControl=robot.lookup(controlId.query();
assertNotNull(“无法通过id=“+controlId,actualControl”)找到控件;
返回实际控制;
}

两者都有。我正在使用基于fxrobot的内部测试框架,该框架调用fxml id。但是该框架没有clickon()方法,因此我必须在这个问题上有所创新。两者都有。我正在使用基于fxrobot的内部测试框架,该框架调用fxml id。但是该框架没有clickon()方法,因此我必须在这个问题上有所创新。