Reputation: 125
I am unable to clear hidden multiple file input using selenium.
HTML source
<input type="file" multiple style="display: none"/>
Selenium
webElement.sendKeys(file1.absolutePath); // 👌🏻 file1 added
webElement.sendKeys(file2.absolutePath); // ⚠ appends file2
webElement.sendKeys(file3.absolutePath); // ⚠ appends file3
/// and so on
Files just continuously appending into the input and there is no obvious way to clear it. I've shown the input element for debugging purposes and all files had been put in the field.
I've tried to use WebElement.clear()
, sendKeys(Keys.BACK_SPACE)
and several others. No one does work with the hidden input element.
Upvotes: 0
Views: 883
Reputation: 9969
Simply grab the tag and use driver.execute
to change the value of that tag.
js = "document.getElement(By.tagName("input")).value = "+file2.absolutePath;
driver.execute_script(js).
Upvotes: 1