However, I did not find the way to click on a specific menu. For example, in my test app, I have two menu items with text “About” and “Rescan”. How do I automatically click on the two menu items?
Sorry, I was not clear that I want the code to work for all apps, but not specific to the two menu items with text “About” and “Rescan”. Therefore, I cannot check the text to locate the menu item. I tested with following code, which seems work. Let me know if you have any other suggestions.
System.out.println("click on menu");
driver.sendKeyEvent(AndroidKeyCode.MENU);
Thread.sleep(3000);
System.out.println("click on menu items");
List<WebElement> menu_items = driver.findElementsByClassName("android.widget.TextView");
System.out.println(""+menu_items.size()+" menu items found");
for (WebElement menu_item:menu_items) {
//click on a menu item
Thread.sleep(3000);
}
Alternatively, you could pass in an index. This has the benefit of being language independent, but you have to map out each menu screen to verify the order of the entries in the menu list.
I think what jeffchenurbana was looking for is a way to find menu item elements that does not depend on the text shown in the UI, to make the appium test resilient to changes to the text strings.
I’m trying to do this with a menu built with NavigationView. With this class, each menu item is a CheckedTextView with resource-id=<package-name>:id/design_menu_item_text and no content-desc set. The only way to distinguish different menu items from each other is via the text attribute, which is less than ideal.
I’m wondering if anyone has found an approach that works.