InvalidArgumentException Thrown Even Though Files are Uploaded in <input type='file'> Tag in Selenium-Java

371 Views Asked by At

I am using Selenium WebDriver and Java to upload two files in a <input type='file'> tag.

I have adopted the way mentioned in this post.

This is my code snippet, to be specific.

wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(fileSelectionBox))).sendKeys
                (System.getProperty("user.dir") + invoiceFilePath + fileNames[0]
                        + "\n"
                        + System.getProperty("user.dir") + invoiceFilePath + fileNames[1]);

The problem is, although the two files are successfully uploaded, and application flow moves forward, I am still getting this exception from the code snippet mentioned above.

org.openqa.selenium.InvalidArgumentException: One or more files could not be selected.

The DOM looks like this.

<span class="w-upload-file__pseudo-button-span relative ">Choose Files</span>
    <div class="w-u-f__abs-button-wrapper "><span class="w-upload-file__pseudo-button-span relative ">Choose Files</span></div>
    <span class="w-upload-file__span" type="text" disabled="">No file selected</span>
    <span class="w-upload-file__input-focus-wrapper"></span>
    <div class="w-upload-file__dropzone-container" tabindex="0" aria-disabled="false"><input type="file" multiple="" autocomplete="off" style="display: none;"></div>
    <input type="file" multiple="" autocomplete="off" style="display: none;">
    <input type="button" pseudo="-webkit-file-upload-button" value="Choose Files">
    <input type="file" multiple="" autocomplete="off" style="display: none;">
    <div class="w-upload-file__dropzone-container" tabindex="0" aria-disabled="false"><input type="file" multiple="" autocomplete="off" style="display: none;"></div>

Xpath of "fileSelectionBox" is "//span[contains(text(), 'No file selected')]/preceding::input[@type='file']"

I need to get rid of this exception. Any idea on this?

0

There are 0 best solutions below