Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we handle Upload File component using Selenium IDE?

Can anyone please provide idea or site reference for handling File Upload Process using Selenium IDE?

Rest of the actions are recording thru' Selenium IDE but this upload process is alone giving trouble...

Thanks Karunagara Pandi

like image 720
Karunagara Pandi Avatar asked Dec 24 '13 04:12

Karunagara Pandi


People also ask

Can we do file upload through 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].

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.


2 Answers

A command like this works for me on Selenium IDE 2.5.0

Command: type
Target:  id=idOfFileInput
Value:   /full/path/to/uploadfile

Now I'm trying to find out how to pass a relative path from the Selenium script :-)

like image 147
Jeroen Kransen Avatar answered Oct 13 '22 08:10

Jeroen Kransen


The general rule of the thumb is that you don't need to automate any "native dialogs" that are part of the web browser itself. What you do instead is recreate the same general function of the HTTP POST using Apache HTTP Utils. So, if the upload button has a URL that it posts the file upload to, all you do is recreate in code the file upload activity and skip using the native "browse for file" dialog and the "submit" button on that dialog. Instead, just manually post the file using code.

I think that is how most Selenium developers do it. In the future, there will be a WebDriver upgrade that adds control over native browser components and they are still working on it. It is called Marionette and the Mozilla foundation is working on it.

like image 42
djangofan Avatar answered Oct 13 '22 09:10

djangofan