Encountered an error while trying to upload a file to a web application using Chrome through Appium

My attempts to upload a file to through Chrome using Appium have consistently resulted in an ERR_ACCESS_DENIED error.

The file I am trying to upload is located in the Download folder on my device.

Please see the image below:

https://i.stack.imgur.com/wU1bS.png

Despite experimenting with various combinations of capabilities such as

noReset, autoGrantPermissions, fastReset
, I have not been able to resolve the issue.

Here is 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()

Although the script executes smoothly until the send_keys step, clicking file-submit triggers the mentioned error. The same scenario occurs when attempting this on .

Details of Versions Used:

  • Appium Version: 1.17.0 (Tried versions ranging from 1.10.x to 1.20.x)
  • Device: Samsung Galaxy S9, Android 10
  • Chromedriver: 90.0.4430.24 (Encountered the same error with Chrome 81)

Attempts Made So Far:

  • I explicitly granted permissions using the following command before starting Appium (and during the script execution in case permission settings reset), but the problem persisted.
adb -P 5037 shell 'pm grant com.android.chrome android.permission.READ_EXTERNAL_STORAGE  android.permission.WRITE_EXTERNAL_STORAGE'
  • In addition to specifying browserName: "Chrome", I also tried providing appPackage and appActivity for launching Chrome, yet without success.

Is there something crucial that I might be overlooking? This process works flawlessly on desktop browsers (using Selenium) but fails to run even once on my mobile device.

Please advise if there are any additional details I should provide.

I've raised an issue on Appium as well: https://github.com/appium/appium/issues/15293

Answer №1

Interestingly, it appears that Chrome encounters obstacles when attempting to access the /sdcard/Download/ directory during Automation.

However, I discovered that uploading a file from the /data/local/tmp/ directory (after transferring the file there first) does actually work.

Notably, there are differences between how Android 9 and Android 10+ handle file download and upload processes in relation to the path /sdcard/Download/ (although I am still investigating the reasons behind this):

  1. For file downloads:
  • Android 10 and higher do not prompt for permission (no dialog box appears)
  • On the other hand, Android 9 (and probably older versions) display a dialog box requesting permission.
  1. Regarding file uploads:
  • In these cases, neither version requests permission, leading to upload failures.

To overcome this issue and successfully upload files, we have two potential solutions:

  1. Utilize an alternative directory such as /data/local/tmp/ (which has shown success on Android 10 and newer).
  2. (For Android 9 and potentially earlier versions) Begin by downloading any file, granting necessary permissions, and then proceed with uploading from the /sdcard/Download/ directory.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The sendKeys command in WebDriver is failing to enter text into the Password field

Currently, I am delving into the world of selenium webdriver automation and have encountered an issue with the sendKeys command not working on Password type fields. After doing some research online, it seems like others are also facing the same problem but ...

What are the steps to keep a web application from closing on Android when the back button is pressed?

I am currently working on a HTML5 web application and packaging it with Cordova (phonegap) 1.7. My goal is to customize the behavior of the Android back button so that instead of closing the application by default, it navigates back using window.history.b ...

Struggling to use XPath to interact with a pop-up window in Selenium

Is there a way to retrieve 'CIK' codes from the 'SEC' using Selenium? When I try running the code, a "survey" pop-up appears that doesn't show up when doing it manually. This causes issues with my code because I can't inspect ...

When attempting to call methods after executing a new Class in Android Studio, the application crashes

I have been working on an app that utilizes JSON data. The issue I am facing is that when I retrieve the JSON using HentData.execute() and assign it to a string variable, my program crashes when I try to perform any operations with it. HentData extends As ...

Selenium is having difficulty clicking on a table row, even though it can be done manually

On my webpage, a table is populated dynamically through an API call. Each row in the finalized table is structured as follows: <tr class="ant-table-row ant-table-row-level-0" data-row-key="0"> <td class="">Value1</td> <td class="" ...

selenium: Reached maximum number of retries for the specified URL

This specific issue has arisen while executing code for a Django application. Initially, the tests were running smoothly, but recently encountered errors in the last four tests involving Selenium. Interestingly, these errors emerged after implementing driv ...

When Selenium in JavaScript cannot locate a button element, use `console.log("text")` instead

I am trying to capture the error when there is no button element available by using console.log("No element"). However, my code is not working as expected. const {Builder, By} = require("selenium-webdriver"); let driver = new Builder().forBrowser("chrome ...

Tips on personalizing the BROWSERSTACK_BUILD_NAME within Jenkins

Currently, I am in the process of incorporating BrowserStack into my Selenium Python framework and utilizing Jenkins for running tests. However, I am encountering difficulties when trying to personalize the build name on the BrowserStack dashboard. ...

Is it recommended to have a single repository for iOS and Android when creating automation for mobile applications (Native App)?

At the moment, I am utilizing Appium, Selenium, Java, and TestNG for automating a native app. My focus is on iOS and Android platforms, where the functionalities are similar but the element identification process differs between the two. Each element has a ...

Having trouble setting the select value with JavaScript in the Selenium web driver

I am working on a web page that includes a cascaded dropdown feature. The data in the second dropdown appears to be generated via ajax based on the selection made in the first dropdown. Here is the code for the first select option: <select class="form- ...

Exploring the Keys of Multiple HashMaps

I am looking to compare the keys of four hashmaps. All of the keys in the hashmaps are the same. However, I want to assess each hashmap to compare the keys of all four hashmaps. In the provided code snippet, I am using 4 nested loops and a logical AND cond ...

Compel the browser to launch a fresh tab

I'm currently working on an app that involves uploading files. One issue I'm facing is that the file system pop up doesn't close after the upload, causing a quarter of the screen to be covered while the test keeps running in the background. ...

Click the button on your mobile device to open the already installed Android app

After creating a small Android app using jQuery Mobile, I incorporated a button to open another native Android app. Is it feasible for the jQuery Mobile app button to load/open an already installed and functioning native Android app upon click? I would gr ...

Can you explain the meaning of arguments[0] and arguments[1] in relation to the executeScript method within the JavascriptExecutor interface in Selenium WebDriver?

When utilizing the executeScript() method from the JavascriptExecutor interface in Selenium WebDriver, what do arguments[0] and arguments[1] signify? Additionally, what is the function of arguments[0] in the following code snippet. javaScriptExecutor.ex ...

Transferring a collection of files in JSON array format

I have a json object that needs to be uploaded, containing nested arrays with files: [{"key":"value","key1":"value1"}, [{"innerkey":"innervalue","filename":"name"},{"innerkey":"innervalue","filename":"name"}]] The two inner keys within the JsonArray repr ...

mistake within the do while loop

public Login ClickGetStatus() { //IWebElement btnGetStatus = driver.FindElement(By.XPath("//*[contains(@id,'GetStatus')]")); do { buttonName_GetStatus[0] = "abc"; Thread.Sleep(3000); bool is_displayed = ...

Using Python with Selenium, retrieve the number of elements impacted by the find_element_by_css_selector method

I am attempting to obtain the count of affected elements through my CSS query. Unfortunately, I have been unsuccessful in retrieving this count. browser = webdriver.Firefox() browser.get("http://just-a-example.site") td_weeks = browser.find_element_by_cs ...

Is there a recommended method for utilizing multiple selenium webdrivers at the same time?

My objective is to create a Python script that can open a specific website, fill out some inputs, and submit the form. The challenge lies in performing these actions with different inputs on the same website simultaneously. I initially attempted using Thr ...

Choose a particular iFrame that contains numerous occurrences of identical names

Currently, I am facing an issue with the 3 iFrames specified on the page I'm working with. Here are their details: <iframe class="col-51" height="560" src="https://attendee.gototraining.com/embed/886b2/catalog/40xxxx bgColor=ffffff" frameborder="0 ...

Is the function "is_element_present" in Selenium WebDriver equivalent to "driver.find_element_by~"?

I am currently creating tests in unittest webdriver selenium Why should I use is_element_present instead of just "find_element_by~" if it contains the same process? def is_element_present(self, how, what): try: self.driver.find_element(by=how, va ...