I am trying to upload a file using Selenium but my input file element is hidden.
My hidden HTML is:
<input id="yui_3_9_0pr3_1_1361897421363_2239" type="file" style="visibility:hidden; width:0px; height: 0px;" multiple="" accept="">
and the select file button HTML is:
<button id="yui_3_9_0pr3_1_1361897421363_2242" class="yui3-button" tabindex="0" aria-label="Select Files" role="button" type="button" style="width: 100%; height: 100%;">Select Files</button>
I tried the same thing using JavascriptExecutor
which you suggested but it still gives an exception ElementNotVisible: Element is not currently visible
.
This is my code:
WebElement fileInput = driver.findElement(By.xpath(//@input[@type='file']));
System.out.println("h14");
String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";
((JavascriptExecutor) driver).executeScript(js, fileInput);
System.out.println("h15");
LocalFileDetector detector = new LocalFileDetector();
String path = "//Users//pdua//Desktop//images.jpeg";
// File f = detector.getLocalFile(path);
//((RemoteWebElement)fileInput).setFileDetector(detector);
System.out.println("h16");
//fileInput.sendKeys(f.getAbsolutePath());
fileInput.sendKeys(path);
The XPath of the hidden input file element is //input[@type='file']
. Not sure if that is right or not!