The Short:
When I trigger a file upload using SendKeys(path) to a proxy element (placed on by ExecuteScript) that then proxies to my hidden through the jquery.fileupload plugin, the file uploads fine, but when I try and issue a FindElement, it blocks until the server responds.
The Long:
I am using the 2.4 C# web driver, default firefox driver, and jquery file upload plugin (blue imp).
The flow begins by clicking a button to open an 'overview dialog box', which has my
<input id="fileUpload" type="file" name="files[]" accept="video/quicktime,video/x-ms-wmv">
<lablel for="fileUpload">Select a file</label>
After composition of the dialog box, I have
jquery('#fileUpload').fileupload(self.fileUploadOptions);
Normal usage has the user click the label, which triggers the input, which then triggers and add callback, which checks size/types, and if OK, then changes to a PROGRESS dialog box, and does a data.submit().
Progress continues until the response, at which time a final dialog box shows some results and can be dismissed with another button.
So, in brief:
- open a dialog
- set template in dialog to intro
- select a file
- change template in dialog to progress
- kick off the ajax (or iframe) upload
- change template in dialog to finish
Selenium couldn't access the fileUpload input (hidden), so to get Selenium to trigger the file upload, I ended up having to execute some script like this:
Add a new input element:
jQuery('', {id: 'tmpId', type: 'file', name:'files[]'}).appendTo('modalDivId')
Trigger a callback:
$('#tmpId').bind('change', function (e) { $('#fileUpload').fileupload('add', { files: e.target.files || [{name: this.value}], fileInput: $(this) }); });
So, now after creating the tmpId input element, my selenium script does this:
var path="\path\to\files";
var tmpInput = WebDriver.FindElement(By.Id("tmpId));
tmpInput.SendKeys(path);
This triggers add callback, checks the file, changes to the template to 'progress', and starts the upload. Assuming the upload takes 60 seconds, the server will respond and then the template will trigger to 'finish'
The problem is that although:
tmpInput.SendKeys(path);
returns 'immediately', so I call
var a = WebDriver.FindElement(By.Id("tmpId"));
And this BLOCKS until the file upload is complete (60 seconds). Even though the progress bar is updating.
And then returns success.
Because I have this progress template I want to validate, I would really like to access the DOM during the upload.
Any thoughts?