How we can use Best Approach to Automate Dropdown Selection in Flutter App Using Appium

I’m currently automating a Flutter-based mobile application using Appium and would appreciate some guidance on handling dropdown elements effectively.

Could you please suggest the best approach?

//customer.java

private static final String CATEGORY_DROPDOWN_KEY = TestKeys.customerCreateEditPageTestKeys.category;
private static final List CATEGORY_OPTION_KEYS = List.of(
“customer_create_edit_page_category_Manager”,
“customer_create_edit_page_category_Employee”,
“customer_create_edit_page_category_Owner”
);

public String selectRandomCategory() throws InterruptedException {
helper.scrollAndClickCategory(driver, flutterFinder, getCategoryDropdownKey());
helper.clickRandomCategory(driver, flutterFinder, getCategoryDropdownKey(), getCategoryOptionKeys());
return “Random category selected”;
}

//helper.java

public void clickRandomCategory(AppiumDriver driver, FlutterFinder flutterFinder, String dropdownKey, List optionKeys) {
try {
flutterFinder.byValueKey(dropdownKey).click();
Thread.sleep(1000); // replace with FluentWait if needed

    boolean optionVisible = false;
    for (String optionKey : optionKeys) {
        try {
            driver.executeScript("flutter:waitFor", flutterFinder.byValueKey(optionKey));
            optionVisible = true;
            break;
        } catch (Exception ignored) {}
    }

    if (!optionVisible) {
        logger.error("No category options appeared.");
        return;
    }

    Collections.shuffle(optionKeys);
    for (String key : optionKeys) {
        try {
            flutterFinder.byValueKey(key).click();
            logger.info("Clicked option: {}", key);
            return;
        } catch (Exception e) {
            logger.warn("Failed to click option '{}': {}", key, e.getMessage());
        }
    }

    logger.error("Could not click any category option.");

} catch (Exception e) {
    logger.error("Dropdown interaction failed: {}", e.getMessage());
}

}

Here’s a summary of the logic:

  • I use flutterFinder.byValueKey() to locate the dropdown and the options via their unique valueKey.
  • After clicking the dropdown, I wait for any one of the option keys to become visible using flutter:waitFor.
  • I then shuffle the list of predefined option keys and attempt to click one of them randomly.

issue:

I’m using the correct Key, but it is not clicking; it is staying for a long time.

Not sure about Flutter BUT with native apps we have difference between iOS and Android with selecting Dropdown. I believe similar should apply for Flutter app.
For example with iOS it is simple setValue to XCUIElementTypePickerWheel - very fast command. With Android you should use enableMultiWindows capability as it list showing in another window.