HI,
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);
elementUpload.sendKeys(locallPath);
}else{
elementUpload.sendKeys(filePath);
}
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);
click(elementUpload);
Set<String> contextNames = ((AndroidDriver) driver).getContextHandles();
for (String strContextName : contextNames) {
if (strContextName.contains("NATIVE_APP")) {
((AndroidDriver) driver).context("NATIVE_APP");
break;
}
}
while (driver.findElements(By.xpath("//*[@class='android.widget.Button'][2]")).size()>0) {
driver.findElement(By.xpath("//*[@class='android.widget.Button'][2]")).click();
break;
}
WebElement sdcardFolder = driver.findElement(By.xpath("//*[@text='SD card']"));
sdcardFolder.click();
WebElement downloadFolder = driver.findElement(By.xpath("//*[@text='Download']"));
downloadFolder.click();
By eleDoc = By.id("com.android.documentsui:id/thumbnail");
waitForVisibility(eleDoc);
driver.findElement(eleDoc).click();
please help me how can I upload a file on mobile android emulator of chrome browser application