I want to upload a file using selenium webdriver, the problem is that the button to upload the file has an input_type=file.
I used xpath, name, ID, with sendkeys and it's not working.
Here is the code:
driver.findElement(By.xpath(".//*[@id='repondants_file']")).sendkeys("filepath");
I have also used JS:
WebElement element = driver.findElement(By.xpath(".//*[@id='repondants_file']"));
JavascriptExecutor executor = (JavascriptExecutor)getDriver();
executor.executeScript("arguments[0].click()",element );
Here is the full stacktrace:
*** Element info: {Using=xpath, value=.//*[@id='repondants_file']}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:133)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:99)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:43)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:371)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:476)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
at TestPackage.OperationProjet2.main(OperationProjet2.java:41)
Here is the Html source code:
a href="http://test.360-feedback-enligne.fr/professionnel-rh/app/batch/encode.php" download="liste_repondants.xlsx">
<br/>
<br/>
<label>Importez le fichier EXCEL des répondants (conforme à la trame) :</label>
<input id="repondants_file" name="repondants_file" type="file"/>
Any clues?
NoSuchElementExceptionby any chance? you should also add the relevant html to the question.