-1

I am trying to upload file by adding

driver.findElementsByXpath("").sendkeys("filepath");

but that is not working.

m00am
  • 5,910
  • 11
  • 53
  • 69
Amni Roy
  • 1
  • 1
  • 1
  • Welcome to SO. I formatted the code in your question so it is easier to read. However, your question is missing some crucial information. PLease take a look at the [how to ask page](https://stackoverflow.com/help/how-to-ask) and edit your question accordingly. – m00am Mar 28 '18 at 12:30

1 Answers1

1

There is no way to repeat that trick from web in native mobile app: simply because it doesn't work that easy here. You have to do it step by step, e.g. click button to open gallery, find image in gallery and click it, etc. On the other hand, there is a push_file end point in Appium to put file on device: https://appium.readthedocs.io/en/latest/en/commands/device/files/push-file/

There is a nice blog post with code sample available here:

File assetDir = new File(classpathRoot, "../assets");
File img = new File(assetDir.getCanonicalPath(), "cloudgrey.png");
driver.pushFile(ANDROID_PHOTO_PATH + "/" + img.getName(), img);

// navigate to photo selection in your app, open gallery and click the recently uploaded image 
dmle
  • 3,498
  • 1
  • 14
  • 22