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:
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:
1.17.0
(Tried version from 1.10.x
to 1.20.x
)What all I have tried:
adb -P 5037 shell 'pm grant com.android.chrome android.permission.READ_EXTERNAL_STORAGE android.permission.WRITE_EXTERNAL_STORAGE'
browserName: "Chrome"
, I have also tried specifying appPackage and appActivity
to begin chrome. But no luck.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
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):
Therefore, as a workaround to upload files, we have two ways of doing so:
/data/local/tmp/
(The only thing I found working for Android 10 and above)./sdcard/Download/
directory.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With