Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I have a complicated interface where uploading a file is three step ( The forum is not allowing me to add screenshots of my window so please try to visualise it) step 1 click on browse tab and select a file to upload( This will create progress bar) step 2 click on start upload button Step 3 click on finish button firebug information about the elements on the page have been pasted at the bottom of the page. Id of my browse button is fileInputUploader

The code I am using to try and upload the file is ( within my test class)

WebElement upload = driver.findElement(By.id("fileInputUploader"));
upload.sendKeys("C:/Users/Deepankur/Desktop/Deepankur Folder/selenium Test Cases/test12.jpg");

But it's not doing anything

I am not able to see that upload progress animation in step 2, so I can click on start upload and finish it. Any help will be much appreciated.

Here is the html for this section of my page

<div style="padding: 20px; border: 2px solid #ccc; margin: 12px 0 0 0; width: 100%;" id="multiUploader">
 <input width="110" type="file" height="30" id="fileInput" name="fileInput" style="display: none;"><object width="110" height="30" type="application/x-shockwave-flash" data="/core/webcore/swf/uploadify.swf" id="fileInputUploader" style="visibility: visible;"><param name="quality" value="high"><param name="wmode" value="opaque"><param name="allowScriptAccess" value="always"><param name="flashvars" value="uploadifyID=fileInput&amp;pagepath=/core/root/&amp;script=/core/application/pApproval/uploadify.cfm&amp;folder=//192.168.100.51/client_data/CPM_ConcretePlatform_DEV/userUploads&amp;scriptData=project_id%3D19%26client_id%3D2172%26project_file_type%3D2%26file_zone_id%3D104%26file_zone_group_id%3D17%26parent_project_file_id%3D0%26approval_rule_id%3D10%26job_id%3D519%26status_id%3D17&amp;width=110&amp;height=30&amp;wmode=opaque&amp;method=POST&amp;queueSizeLimit=20&amp;simUploadLimit=1&amp;fileDesc=Please see the list of allowed file extensions under More Help Uploading&amp;fileExt=*.jpg;*.tif;*.pdf;*.qxd;*.eps;*.psd;*.zip;*.doc;*.ppt;*.xls;*.pdf;*.mov;*.ai;*.png;*.bmp;*.ait;*.dwg;*.dxf;*.flv;*.indd;*.txt;*.inx;*.gif;*.cad;*.docx;*.xlsx;*.pptx;*.mpp;*.m2v;*.avi;*.vob;*.mpg;*.wmv;*.mp4;*.m4v;*.misc;*.ppsx&amp;multi=true&amp;sizeLimit=26214400&amp;fileDataName=Filedata"></object><div class="uploadifyQueue" id="fileInputQueue"></div>
 <br>
 <br>
 <a class="uploadButton" href="javascript:$('#fileInput').uploadifyUpload(); uploadStartFinishButton();">Start Upload</a> 
</div>
share|improve this question
    
add comment

3 Answers

In my opinion, it is not good coding practice (in terms of writing Selenium tests) to try to automate a browsers native file upload dialog. People are doing it, and it is certainly possible, but it's much slower and inefficient and doesn't prove anything significant in an area that is already tested thoroughly by the publishers of the web browser you are automating.

Instead, for every file upload action in a web application, there should be a remote URL which that file upload control is posting to. Your developers should allow you, as a Selenium test writer, to access that URL directly and POST the file through a direct upload using Apache HttpUtils.

share|improve this answer
add comment

Try Calling sendKeys method with FileUrl.

File file=new File("C:/SomeFolder/a.jpg");
URL url=file.toURL();

I had a similar problem and got it worked via FileUrl, however it is in C#. Hope the above would work in Java.

share|improve this answer
add comment

Your file upload control is implemented in Flash; Webdriver doesn't have any in-built way of interacting with flash objects, so that's why your TypeKeys isn't working.

There are various add-ons which you could look into for automating the flash object, Sikuli for example.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.