FileUpload with HtmlUnit doesn't fire fileUploadListener-Event (automatically loads Primefaces)

I am trying to automate file uploads using WebDriver. It works fine for ChromeDriver and FirefoxDriver, but refuses to work with HTMLUnit.

I had read

Using Webdriver to Download PrimeFaces Files

https://stackoverflow.com/questions/21753497/unable-to-automate-filling-of-form-with-file-upload-using-htmlunit

Unable to load file using Selenium web driver

but both weren't helpful.

The selenium (java) code for this download action is simple:

String elementXPath = "//input[contains(@id,'FileUpload_input')]";
WebElement element = driver.findElement(By.xpath(elementXPath));
element.sendKeys(pathToFile);

      

The html code for the inputElement:

<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>

      

perhaps you need something-pricelist-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, this is picure-Upload. A notable characteristic of this download is that there is no confirmation button or submit button.

The testautomation program works fine for major browsers, but does not work with htmlUnit. After several hours of debugging, I can confirm that htmlUnit is executing the 'sendKeys'-Methode, but that does not call the fileUploadListener. I have already tried to click other elements, so there is focusLost-Action, but it didn't help. Indeed, "driver.getPageSource ()" after sending sendKeys:

<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 now there are buttons ... why? I was still trying to click the button with xPath "//td[@class='start']//button"

, but still nothing happened. No Fileupload.

HtmlDriver has javascript enabled and also I am using NicelyResynchronizingAjaxController (). I've already tried waiting more than 30 seconds, but it still doesn't work.

Is there someone out there who knows this problem and this solution ... or at least a workaround?

+3


source to share


1 answer


I found a solution myself. I was still using selenium 2.40, upgrading to 2.42 resolved the issue, although the changelog did not suggest a possible fix for my problem.



0


source







All Articles