Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium IDE - Upload file into field

I'm creating a testing suite to automate some parts of data input on my web application. I have a page where I can click on a button to upload a document to the application. It looks something like this:

screenshot 1

Once the Add New Attachment button is clicked, it opens the browser's file explorer to select a document to upload. I'm trying to replicate this within Selenium IDE.

Here is what it looks like as of now:

screenshot 2

However, this part seems to fail. Does anyone know how to achieve a similar process using Selenium IDE? I'm on Chrome and Firefox.

like image 644
FlameDra Avatar asked May 14 '18 17:05

FlameDra


People also ask

How do I import files into Selenium IDE?

From the menu bar, select File > Import Selenium IDE Project and browse your Selenium IDE file (a single file with a . side extension) to open.

Can we do file upload thru Selenium?

We can upload files using Selenium Webdriver. This is achieved by the sendKeys method. We have to first identify the element which performs the file selection by mentioning the file path [to be uploaded].


2 Answers

If you get the

{"code":-32000,"message":"Not allowed"}

on Chrome, follow the steps below:

Window > More Tools > Extensions > Selenium IDE > Details

Then turn on the 'Allow access to file URLs' option.

I was having the same problem and this worked for me.

like image 156
AndreVitorio Avatar answered Oct 09 '22 15:10

AndreVitorio


It is possible to upload the files using selenium IDE. It can be done as mentioned below.

|Command|Target|Value|

|type|target_location_path|location_of_the_file_in_your_system|

Example:

|type|id=ConsignmentCustomerInvoiceFilename|C:\Users\abc\Desktop\img1.jpg|

You can identify the "target_location_path" by manually uploading the file and then finding the xpath of the uploaded file in the web app.

Please refer below screenshot to get a better understanding.

SeleniumIDE_uploadfile

You can add the system path to the IDE test by using the below code.

<tr>
    <td>storeEval</td>
    <td>Preferences.getString(TestSuite.TEST_SUITE_DIRECTORY_PREF);</td>
    <td>testSuiteFolder</td>
</tr>
<tr>
    <td>type</td>
    <td>id=QuestionUpload_file</td>
    <td>${testSuiteFolder}/resources/question_upload.csv</td>
</tr>
like image 42
Antony Lobo Avatar answered Oct 09 '22 15:10

Antony Lobo