File upload - Measuring tool for angles

I struggle with using protractor because some tests require file uploads. This is an example of my HTML structure:

<div class="panel-footer">
    <ul class="list-unstyled">
      <!-- ngRepeat: file in imagesToUpload -->      
    </ul>
    <button class="btn btn-sm btn-success pull-right ng-binding ng-hide" ng-show="imagesToUpload.length" ng-click="uploadImages()">Upload to Server</button>
    <button class="btn btn-sm btn-primary ng-binding" ng-file-select="onImageSelect($files)" data-multiple="true" style="overflow: hidden;">Choose Files<input type="file" class="btn btn-sm btn-primary ng-binding" ng-file-select="onImageSelect($files)" data-multiple="true" multiple="multiple" __wrapper_for_parent_="true" style="width: 1px; height: 1px; opacity: 0; position: absolute; padding: 0px; margin: 0px; overflow: hidden;"></button>
  </div>

Here is the input HTML:

<input type="file" class="btn btn-sm btn-primary ng-binding" ng-file-select="onImageSelect($files)" data-multiple="true" multiple="multiple" __wrapper_for_parent_="true" style="width: 1px; height: 1px; opacity: 0; position: absolute; padding: 0px; margin: 0px; overflow: hidden;">

I have researched extensively on this problem with protractor, and most suggestions revolve around manually pasting the file path into the input field and then clicking "UPLOAD". However, in my case, the issue is that the input stores an object rather than a PATH.

If I manually select a file, it shows up in the HTML like this:

<li ng-repeat="file in imagesToUpload" class="ng-binding ng-scope">
        FileName.png <span title="remove" class="btn btn-flat glyphicon glyphicon-remove" ng-click="imagesToUpload.splice($index, 1)"></span>
      </li>

I'm wondering if there might be another approach to solving this issue. Perhaps creating an object and sending it there or something similar?

Any advice would be greatly appreciated.

Answer №1

The most popular method for uploading a file using protractor/selenium is to directly input the file path into the file field without triggering the unpredictable upload file dialog:

var uploadInput = element(by.css("input[type=file]"));
uploadInput.sendKeys("path/to/file");

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

Is there a way to instantly create hyperlinks for text that follows the @ symbol?

I am looking for a way to automatically link mentions of user accounts on my website, such as @Melon or @Banana, using JavaScript. For example, I want @Banana to be linked to example.com/users/Banana. Additionally, I would like the linking functionality to ...

Is there a different option to use instead of time.sleep() when web scraping with Selenium in Python?

I am currently working on a project that involves scraping prices for specific food items based on different locations across the country. One of the features allows users to enter the name of a city in an input text box and then view a list of available i ...

Styling Result received from Web API call within an array

I am currently working on a function call that retrieves the result of an SQL query in an array format. app.get('/alluser', (req, res) => { console.log("All Users") user.getAllUsers(function (err, result) { if (!err) ...

Submitting files using the HTML5 File API for server-side processing

I currently have a form set up like this: <form> ... <input type="file" multiple="multiple" id="images" /> <a id="add">Add</a> ... <input type="submit" value="Submit" /> </form> Upon clicking the ad ...

There seems to be an issue with the import class for React PropTypes. The prop

I have multiple oversized items that are utilized in numerous components, so I created a PropTypes file for each item. For example: PropTypes/PropLargeObject.js This file contains: import PropTypes from "prop-types"; const PropLargeObject = Prop ...

How can we make it simple for users to update webpage content using a file from their computer?

I am developing a custom application specifically for use on Firefox 3.6.3 in our internal network. My goal is to dynamically update the content of the page based on a file stored locally on my computer. What would be the most straightforward approach to ...

Google is currently unable to provide the accurate latitude and longitude of the current position

I'm looking to incorporate geolocation functionality into my Laravel project. I've implemented this code, but it seems to be giving me slightly different latitude and longitude values. function getLocation() { var x = document.getElementById( ...

Retrieve the data from an HTTP Request using AngularJS

I've been working on creating a JavaScript function that sends an HTTP Request to retrieve data, but I'm struggling with how to handle and use the result in another function. Here are the two functions I've tried (both intended to achieve t ...

Switch out a scheduled 'click' event for setInterval with mouseenter and mouseexit

I've been struggling with this task for a while and can't seem to figure it out. I've been experimenting with this JSFiddle but I can't change the trigger from click to hover or mouse enter/exit. I tried implementing suggestions from si ...

Creating an array of images using input fields and showcasing them as a dynamic slider

I'm currently working on a challenge involving creating an array of images using an input field and then displaying the array of images as a slider in JavaScript. If anyone can help me, please provide a solution. Could you kindly share the JavaScript ...

jQuery is displaying fields inside the widget box that were supposed to have been removed

I am currently working on a project with a widget foldable box function called Metadata Widget. This widget displays certain fields, and I have added an import button to the side that calls upon the Metadata Widget and shows it. However, I have noticed tha ...

How can I access the value of a textbox within a dynamically generated div?

In my project, I am dynamically creating a div with HTML elements and now I need to retrieve the value from a textbox. Below is the structure of the dynamic content that I have created: <div id="TextBoxContainer"> <div id="newtextbox1"> // t ...

I found myself in a bit of a predicament as I tried to transition a petite

Recently, I've been working on a small project that is built using pure HTML, CSS, and JavaScript. As I am delving into the realm of Vue.js, I decided to challenge myself by migrating this project to Vue.js. Here is how it currently functions with Ja ...

Updating textures in Three.js

Is there a way to access and modify the data in an exported JSON file using JavaScript? For instance, if I have a material with specific properties like mapDiffuse value that I want to change, how can I achieve this through a JavaScript function? "materia ...

RSelenium: encountering difficulties in entering text into text box

The code provided is functioning properly, except for the issue with inputting text into the longitude and latitude fields. These fields seem to be unresponsive for unknown reasons. Can anyone offer assistance in resolving this problem? library(RSeleniu ...

Having difficulty setting up Selenium with Edge on a Mac device

I'm having issues setting up Selenium to work with Python on a Mac running Big Sur. Here are the steps I followed for my current failed configuration: First, I installed Selenium on my Python environment using pip install selenium Next, I downloaded ...

Manipulate the DOM elements within the ng-repeat directive

Hello, I am currently new to AngularJS and have just begun learning how to create directives. While working on a sample project, I encountered an issue with accessing DOM elements rendered inside my directive. Some elements were not accessible in the link ...

Tips for computing values with changing ng-model identifiers

In my angular application, I have a function that creates tables using directives. Each field in the tables must have unique ng-model names so that I can calculate each table individually. To achieve this, I implemented a counter that increments with each ...

Tips for displaying a prompt in the browser window using a blob response from the server

I am facing an issue with the exportChallenges button on a kendo grid in my web application. The button is supposed to export grid data to excel by using an AngularJs factory. However, when I receive the rest service response as a Blob from the server side ...

Connecting elements within an object using VueJs

Within my object "info_login," I gather account information: async created() { try { const res = await axios.get(inscriptionURL); this.comptes = res.data; this.comptes.forEach(element => { const data = {'pseudo': ...