Rohan Chougule
Rohan Chougule

Reputation: 150

Appium - File upload to web using Chrome - ERR_ACCESS_DENIED

I am trying to upload a file to https://the-internet.herokuapp.com/upload via Chrome using Appium. But it leads to ERR_ACCESS_DENIED error all the time.

The file resides in the Download folder of my device.

Refer the image below:

enter image description here

I have tried the following capabilities as well with different combinations, but it didn't help: noReset, autoGrantPermissions, fastReset.

My Script:


from appium import webdriver
import time

def execute_script():
  driver = webdriver.Remote(
      command_executor='http://0.0.0.0:4723/wd/hub',
      desired_capabilities={
          "platform": "android",
          "platformName": "android",
          "platformVersion": "10",
          "deviceName": "<xxxx>",
          "udid": "<xxxx>",
          "browserName": "chrome",
          "automationName": "UIAutomator2",
          "chromeOptions": {
              "w3c": False
          },
          # "autoGrantPermissions": True,
          # "noReset": True,
          # "fastReset": True,
          # "fullReset": False
      }
  )

  driver.get('https://the-internet.herokuapp.com/upload')

  up = driver.find_element_by_id("file-upload")
  up.send_keys("/sdcard/Download/file.pdf")
  driver.find_element_by_id("file-submit").click()

  driver.quit()

driver = execute_script()

The script executes fine till the send_keys step. But as soon as the file-submit click is performed, it leads to the mentioned error. I tried it on https://fileconvoy.com/ as well and it results in the same error.

Version Details:

What all I have tried:

adb -P 5037 shell 'pm grant com.android.chrome android.permission.READ_EXTERNAL_STORAGE  android.permission.WRITE_EXTERNAL_STORAGE'

Is there anything that I am fundamentally missing? This works fine on desktop browsers (using selenium). But I haven't been able to run it once on my mobile device.

Let me know if there is anything else that I should share.

Have created an issue on Appium as well: https://github.com/appium/appium/issues/15293

Upvotes: 7

Views: 1381

Answers (1)

Rohan Chougule
Rohan Chougule

Reputation: 150

It turns out, Chrome can't access /sdcard/Download/ directory during Automation.

Trying to upload a file from /data/local/tmp/ directory (by pushing a file there first) worked.

Secondly, there is a slight difference between Android 9 and Android 10+ considering the file download and upload scenarios for the path /sdcard/Download/ (yet to come up with a reasoning for this):

  1. In case of file download:
  • Android 10 and above don't ask for any permission (i.e. no dialog box pops up)
  • Android 9 (and probably below that), opens up a dialog box asking for the permission.
  1. In case of file upload:
  • None of them ask for any permission, and thus the upload fails.

Therefore, as a workaround to upload files, we have two ways of doing so:

  1. Either using some other directory, i.e. /data/local/tmp/ (The only thing I found working for Android 10 and above).
  2. (For Android 9 and probably below too) Download any file first, allow/accept the permissions requested. Then proceed to upload from the /sdcard/Download/ directory.

Upvotes: 1

Related Questions