Reputation: 159
I am facing an issue with the file upload with WebDriver, using Java, on Firefox 24. And I can NOT use some external program like AutoIT or similar.
I have to upload a file to a section which's HTML code is:
<td>
<input type="file" name="file">
</td>
And what I was using in Eclipse is
pageObject.getTypeFileLocation().sendKeys(textFile);
pageObject.getUploadButton.click();
which does not work; also tried the first answer of this question but neither did the trick.
The test returns 'OK', but I suspected that nothing was being done so added a check to wait for 'Upload complete' text present; But the file is not uploaded, and timeouts after 20 seconds, even when the file to upload is 5KB and takes less than a second when manually uploaded.
The input=file
section contains a button and a 'No File Selected' text that changes to the filepath when a file is selected manually; and this is in what I am basing my idea that the file is not being upload; because the 'No File Selected' remains until the test fails.
I tried this on Chrome and seems to be working fine, and I know that there have been some reworks about input=file
in FF since release 23, but mostly pointed to CSS styling, so I don't think it's related.
Also, a question that might sound kind of stupid, but questions are questions: Doesn't the sendKeys()
action need a field to input those keys? I feel that the WebDriver is trying to write the path over a button, which can't perform the action as it's only a button.
Any help will be appreciated, and thanks in advance!
Upvotes: 0
Views: 1818
Reputation: 159
Solved it!
Don't know if it works for all browsers, but at least it does on FF and Chrome:
Found out that somebody used the FILE type, so reused it and got its absolute path:
protected File *fileName* = new File("*path to file*");
private String textFile = *fileName*.getAbsolutePath();
pageObject.getInput().sendKeys(textFile);
Hope somebody else finds it useful; as it's weird to be answering my own question.
Upvotes: 3