I am having difficulty managing the 'select files to load' dialog using Selenium WebDriver. Here is the HTML code snippet:
<form class="upload">
<button class="btn" data-capture="" type="button">Browse</button>
<input class="hide" type="file" accept="..." multiple="" data-file-input=""/>
</form>
My goal is to:
- Remove the 'hide' class;
- Send keys with file path after the element is visible;
- Hide the element again.
This is the code I have written to achieve this:
JavascriptExecutor js = (JavascriptExecutor) webDriver;
js.executeScript("$('.hide:not(.layout)').removeClass('hide')");
(webDriver.findElement(By.cssSelector(".upload>input"))).sendKeys("path_to_file");
js.executeScript("$('.hide:not(.layout)').addClass('hide')");
However, I encountered an exception on the 3rd line:
"Runtime.evaluate threw exception: TypeError: Cannot read property 'click' of null"
What could be causing this issue?