I'm trying to automate a file-upload with WebDriver. It works fine for ChromeDriver and FirefoxDriver, but refuses to work for HTMLUnit.
I've already read
Using Webdriver for PrimeFaces file upload
Unable to upload file using Selenium web driver
but both were not helpfull.
The selenium (java)code for this upload-action is quiete simple:
String elementXPath = "//input[contains(@id,'FileUpload_input')]";
WebElement element = driver.findElement(By.xpath(elementXPath));
element.sendKeys(pathToFile);
The html-code of the inputElement is:
<div class="fileupload-buttonbar ui-widget-header ui-corner-top">
<label class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left fileinput-button" role="button" aria-disabled="false">
<span class="ui-button-icon-left ui-icon ui-icon-plusthick"></span>
<span class="ui-button-text">Upload</span>
<input type="file" id="form:FileUpload_input" name="form:FileUpload_input">
</label>
</div>
<div class="fileupload-content ui-widget-content ui-corner-bottom">
<table class="files"></table>
</div>
maybe necessary, the primefaces-codesnippet of the input-Element:
<div class="#{modalDialog ? 'span5' : 'span6'}">
<p:fileUpload id="FileUpload" mode="advanced" auto="true" sizeLimit="2097152" fileUploadListener="#{ClassView.handleFileUpload}"
label="Upload" allowTypes="/(\.|\/)(gif|GIF|jpe?g|JPE?G|png|PNG)$/" process="@this"
showButtons="false"/>
</div>
As you can see, it's a picure-Upload. The noteworthy characteristic of this upload is, that there is no 'confirm'- or 'submit'-button.
The testautomation works fine for the main-browsers, but fails with htmlUnit. After hours of debugging, I can confirm, that htmlUnit performs the 'sendKeys'-Methode, but this doesn't trigger the fileUploadListener. I already tried to click other Elements, so there is a focusLost-Action, but that didn't help. Indeed, a 'driver.getPageSource()' after the 'sendKeys' delivers:
<div class="fileupload-buttonbar ui-widget-header ui-corner-top">
<label class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left fileinput-button" role="button" aria-disabled="false">
<span class="ui-button-icon-left ui-icon ui-icon-plusthick"></span>
<span class="ui-button-text">Upload</span>
<input id="form:FileUpload_input" name="form:FileUpload_input" value="correct\path\to\file\pic.png" type="file" >
</label>
</div>
<div class="fileupload-content ui-widget-content ui-corner-bottom">
<table class="files">
<tbody align="left">
<tr class="template-upload" style="">
<td class="preview"></td>
<td class="name">pic.png</td>
<td class="size"></td>
<td class="progress">
<div class="ui-progressbar ui-widget ui-widget-content ui-corner-all" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="100">
<div class="ui-progressbar-value ui-widget-header ui-corner-left ui-corner-right" style="width: 100%; display: block;"></div>
</div>
</td>
<td class="start">
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-state-hover" type="submit">
<span class="ui-button-icon-left ui-icon ui-icon ui-icon-arrowreturnthick-1-n"></span>
<span class="ui-button-text">ui-button</span>
</button>
</td>
<td class="cancel">
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only">
<span class="ui-button-icon-left ui-icon ui-icon ui-icon-cancel"></span>
<span class="ui-button-text">ui-button</span>
</button>
</td>
</tr>
</tbody>
</table>
</div>
So there are now buttons...why?
I still tried to click the button with xPath "//td[@class='start']//button"
but still nothing happend. No Fileupload.
HtmlDriver has javascript enabled and also I'm using NicelyResynchronizingAjaxController(). I already tried waiting for over 30 Seconds but still that doesn't work.
Is there someoone who knows this problem and it's solution...or at least a workaround?