Don't know how to get to download folder on Android


we have a requirement to upload file for our browser based application,
Flow: when user clicks on upload button → it will ask permission to allow → then it will ask to open Media files → it will land on recent folder , but from here I want to navigate to download folder since all my file moved into downloads folder form local using appium+ selenium

1st approach works on desktop version (chrome) but this approach attaching the file to the application and when I click on submit then application throwing error.

Approach1: boolean isEnabled = elementUpload.isEnabled();

 if (isEnabled) {
                if (PlatformUtils.isMobile(driver)) {
                    File file = new File(filePath);
                    String locallPath="/sdcard/download/" + file.getName();
                    ((AndroidDriver) driver).pushFile("/sdcard/download/" + file.getName(), file);

Approach2: since approach 1 is not working for mobile I want to implement for mobile but here I am not able to navigate to downloads folder

boolean isEnabled = elementUpload.isEnabled();
            if (isEnabled) {
                if (PlatformUtils.isMobile(driver)) {
                    File file = new File(filePath);
                    ((AndroidDriver) driver).pushFile("/sdcard/download/" + file.getName(), file);


                    Set<String> contextNames = ((AndroidDriver) driver).getContextHandles();
                    for (String strContextName : contextNames) {
                        if (strContextName.contains("NATIVE_APP")) {
                            ((AndroidDriver) driver).context("NATIVE_APP");
while (driver.findElements(By.xpath("//*[@class='android.widget.Button'][2]")).size()>0) {
WebElement sdcardFolder = driver.findElement(By.xpath("//*[@text='SD card']"));;

        WebElement downloadFolder = driver.findElement(By.xpath("//*[@text='Download']"));;

By eleDoc ="");

please help me how can I upload a file on mobile android emulator of chrome browser application

Something like this:

Yes, my code also similar to this but there not mentioned how its moved to download folder , in my case when I select Files icon its moving to Recent folder (not downloads folder) from here I want to navigate to ‘Downloads’ folder since my files under download folder

is there any way to move download folder ?

and selecting or click on Media file also some times working ,sometimes not…really pathetic experience

How do you do it manually? Appium is not magic, do it the same way.

Manual way: I will move file local to device local and then attach the file to my browser application. It works without any issues.

Automation: uploadElment.sendkeys. is attaching the file to the application and this looks easy , but after hitting submit, it is throwing an error, which means the application is not accepting it on the mobile browser.
so I followed the second way.
i.e., by interacting with all the above elements one by one but facing issues like
Now I can navigate to the download folder, attach the file, and it is working fine.
but in my tests a couple of times I need to attach different files (1st csv file, 2nd xls file, 3rd pdf file). When I run the test, the first file works fine, but the second time onwards I fail to click on the ‘Media’ file.

Yes, Appium is not magic but when we dont everything looks magic

I need helping hands to make it work my tests smoothly without any issue