Unable to find element in nested FrameLayout in android app

NoSuchElement exception is shown when trying to tap on element available under nested FrameLayout.
@Aleksei can you please help in this. just suggest me how to traverse to this button in the pop up message.

And where is code that fail?

I am using below mentioned code to click on ‘Add’ button in pop up message:

MobileElement frame = aDriver.findElementsByClassName("android.widget.FrameLayout").get(3);
aDriver.switchTo().frame(frame);

MobileElement confirmbtn = frame.findElementById("buttonPanel").findElementById("button1");
confirmbtn.click();

aDriver.switchTo().defaultContent();

Below mentioned are the Appium logs i have marked error as bold.

[HTTP]
[HTTP] --> POST /wd/hub/session/dd5f1c5b-ce3a-457d-a9ee-71e517f5b251/elements
[HTTP] {“using”:“class name”,“value”:“android.widget.FrameLayout”}
[W3C (dd5f1c5b)] Calling AppiumDriver.findElements() with args: [“class name”,“android.widget.FrameLayout”,“dd5f1c5b-ce3a-457d-a9ee-71e517f5b251”]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Waiting up to 10000 ms for condition
[WD Proxy] Matched ‘/elements’ to command name ‘findElements’
[WD Proxy] Proxying [POST /elements] to [POST http://127.0.0.1:8201/wd/hub/session/a487da33-c79f-4655-8903-3a11e2e824f9/elements] with body: {“strategy”:“class name”,“selector”:“android.widget.FrameLayout”,“context”:"",“multiple”:true}
[WD Proxy] Got response with status 200: {“sessionId”:“a487da33-c79f-4655-8903-3a11e2e824f9”,“value”:[{“ELEMENT”:“cfe38c5c-fc85-4076-bc57-e9147fade041”,“element-6066-11e4-a52e-4f735466cecf”:“cfe38c5c-fc85-4076-bc57-e9147fade041”},{“ELEMENT”:“1bb096e0-2f5c-470c-948c-b0c490beabb0”,“element-6066-11e4-a52e-4f735466cecf”:“1bb096e0-2f5c-470c-948c-b0c490beabb0”},{“ELEMENT”:“654e6d6c-342b-4252-9fd1-e07e28fde314”,“element-6066-11e4-a52e-4f735466cecf”:“654e6d6c-342b-4252-9fd1-e07e28fde314”},{“ELEMENT”:“d09ed02f-74cf-4691-8400-24c4f0981400”,“element-6066-11e4-a52e-4f735466cecf”:“d09ed02f-74cf-4691-8400-24c4f0981400”},{“ELEMENT”:“678a969f-2dfb-4066-a468-7b3cfaf95879”,“element-6066-11e4-a52e-4f735466cecf”:“678a969f-2dfb-4066-a468-7b3cfaf95879”},{“ELEMENT”:“4cd1457a-0978-457d-9c84-d7c095b3726a”,“element-6066-11e4-a52e-4f735466cecf”:“4cd1457a-0978-457d-9c84-d7c095b3726a”},{“ELEMENT”:“5d565c78-5124-490c-98d8-d3fba71dd178”,“element-6066-11e4-a52e-4f735466cecf”:“5d565c78-5124-490c-98d8-d3fba71dd178”}]}
[W3C (dd5f1c5b)] Responding to client with driver.findElements() result: [{“element-6066-11e4-a52e-4f735466cecf”:“cfe38c5c-fc85-4076-bc57-e9147fade041”,“ELEMENT”:“cfe38c5c-fc85-4076-bc57-e9147fade041”},{“element-6066-11e4-a52e-4f735466cecf”:“1bb096e0-2f5c-470c-948c-b0c490beabb0”,“ELEMENT”:“1bb096e0-2f5c-470c-948c-b0c490beabb0”},{“element-6066-11e4-a52e-4f735466cecf”:“654e6d6c-342b-4252-9fd1-e07e28fde314”,“ELEMENT”:“654e6d6c-342b-4252-9fd1-e07e28fde314”},{“element-6066-11e4-a52e-4f735466cecf”:“d09ed02f-74cf-4691-8400-24c4f0981400”,“ELEMENT”:“d09ed02f-74cf-4691-8400-24c4f0981400”},{“element-6066-11e4-a52e-4f735466cecf”:“678a969f-2dfb-4066-a468-7b3cfaf95879”,“ELEMENT”:“678a969f-2dfb-4066-a468-7b3cfaf95879”},{“element-6066-11e4-a52e-4f735466cecf”:“4cd1457a-0978-457d-9c84-d7c095b3726a”,“ELEMENT”:“4cd1457a-0978-457d-9c84-d7c095b3726a”},{“element-6066-11e4-a52e-4f735466cecf”:“5d565c78-5124-490c-98d8-d3fba71dd178”,“ELEMENT”:“5d565c78-5124-490c-98d8-d3fba71dd178”}]
[HTTP] <-- POST /wd/hub/session/dd5f1c5b-ce3a-457d-a9ee-71e517f5b251/elements 200 64 ms - 907
[HTTP]
[HTTP] --> POST /wd/hub/session/dd5f1c5b-ce3a-457d-a9ee-71e517f5b251/frame
[HTTP] {“id”:{“ELEMENT”:“d09ed02f-74cf-4691-8400-24c4f0981400”,“element-6066-11e4-a52e-4f735466cecf”:“d09ed02f-74cf-4691-8400-24c4f0981400”}}
[W3C (dd5f1c5b)] Driver proxy active, passing request on via HTTP proxy
[WD Proxy] Matched ‘/wd/hub/session/dd5f1c5b-ce3a-457d-a9ee-71e517f5b251/frame’ to command name ‘setFrame’
[WD Proxy] Proxying [POST /wd/hub/session/dd5f1c5b-ce3a-457d-a9ee-71e517f5b251/frame] to [POST http://127.0.0.1:8201/wd/hub/session/a487da33-c79f-4655-8903-3a11e2e824f9/frame] with body: {“id”:{“element-6066-11e4-a52e-4f735466cecf”:“d09ed02f-74cf-4691-8400-24c4f0981400”,“ELEMENT”:“d09ed02f-74cf-4691-8400-24c4f0981400”}}
[HTTP] <-- POST /wd/hub/session/dd5f1c5b-ce3a-457d-a9ee-71e517f5b251/frame - - ms - -
[HTTP]
[HTTP] --> POST /wd/hub/session/dd5f1c5b-ce3a-457d-a9ee-71e517f5b251/frame
[HTTP] {“id”:{“ELEMENT”:“d09ed02f-74cf-4691-8400-24c4f0981400”,“element-6066-11e4-a52e-4f735466cecf”:“d09ed02f-74cf-4691-8400-24c4f0981400”}}
[W3C (dd5f1c5b)] Driver proxy active, passing request on via HTTP proxy
[WD Proxy] Got an unexpected response with status undefined: {“code”:“ESOCKETTIMEDOUT”,“connect”:false}
[WD Proxy] Matched ‘/wd/hub/session/dd5f1c5b-ce3a-457d-a9ee-71e517f5b251/frame’ to command name ‘setFrame’
[WD Proxy] Proxying [POST /wd/hub/session/dd5f1c5b-ce3a-457d-a9ee-71e517f5b251/frame] to [POST http://127.0.0.1:8201/wd/hub/session/a487da33-c79f-4655-8903-3a11e2e824f9/frame] with body: {“id”:{“element-6066-11e4-a52e-4f735466cecf”:“d09ed02f-74cf-4691-8400-24c4f0981400”,“ELEMENT”:“d09ed02f-74cf-4691-8400-24c4f0981400”}}
[W3C (dd5f1c5b)] Encountered internal error running command: Error: Could not proxy. Proxy error: Could not proxy command to remote server. Original error: Error: ESOCKETTIMEDOUT
[W3C (dd5f1c5b)] at doJwpProxy (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:490:13)
[W3C (dd5f1c5b)] at process._tickCallback (internal/process/next_tick.js:68:7)
[HTTP] <-- POST /wd/hub/session/dd5f1c5b-ce3a-457d-a9ee-71e517f5b251/frame - - ms - -
[HTTP]
[WD Proxy] Got an unexpected response with status undefined: {“code”:“ESOCKETTIMEDOUT”,“connect”:false}
[W3C (dd5f1c5b)] Encountered internal error running command: Error: Could not proxy. Proxy error: Could not proxy command to remote server. Original error: Error: ESOCKETTIMEDOUT
[W3C (dd5f1c5b)] at doJwpProxy (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:490:13)
[W3C (dd5f1c5b)] at process._tickCallback (internal/process/next_tick.js:68:7)

@Aleksei @mykola-mokhnach I have posted this issue on github also.(as of now displayed as last comment.)

@Aleksei I Have tried below mentioned code also, it’s also not working for me:

List<AndroidElement> frame = aDriver.findElementsByClassName("android.widget.FrameLayout");
int size = frame.size();
int i;
MobileElement currentFrame = null;
for(i =0; i<4; i++) {
currentFrame = (MobileElement) aDriver.switchTo().frame(i);
aDriver.switchTo().defaultContent();
}
MobileElement confirmbtn = currentFrame.findElementById("parentPanel").findElementById("buttonPanel").findElementById("android:id/button1");
confirmbtn.click();

try:

        List<MobileElement> elements = driver.findElements(MobileBy.AndroidUIAutomator("new UiSelector().resourceIdMatches(\".*id/button1\")"));
        System.out.println("elements size: " + elements.size());
        TapOptions tapOptions;
        try {
            tapOptions = new TapOptions().withElement(ElementOption.element(elements.get(0))); // first 'button1' button
            new TouchAction(driver).tap(tapOptions).perform();
        } catch (Exception e) {
            e.printStackTrace();
        }

@Aleksei thanks for your help.I’ll try this code and update you.