I have following method that uploads image using selenium.
public static void uploadSampleImage(StaticSeleniumDriver driver)
{
File file = new File(System.getProperty("user.dir") + "/resources/images/" + SAMPLE_DOCUMENT_FILE_NAME);
Utils.Log("file exists: " + file.exists());
String imagePath = file.getAbsolutePath();
WebElement input = driver.findElement(By.name("file"));
input.sendKeys(imagePath);
}
That's a standard way of feeding file path (like explained in Guru99 tutorial) to upload file.
org.openqa.selenium.InvalidArgumentException: invalid argument: File not found : /usr/src/app/resources/images/image2.png (Session info: chrome=72.0.3626.81) (Driver info: chromedriver=2.46.628388 (4a34a70827ac54148e092aafb70504c4ea7ae926),platform=Linux 4.9.125-linuxkit x86_64) (WARNING: The server did not provide any stacktrace information)
Which is weird because I am sure file exist in given directory (in my method above, I am checking if file exists and log clearly confirms that)
Any suggestions would be welcome, thank you
For RemoteWebDriver
you have to set file detector driver.setFileDetector(new LocalFileDetector());
.
Your code:
public static void uploadSampleImage(StaticSeleniumDriver driver)
{
driver.setFileDetector(new LocalFileDetector());
File file = new File(System.getProperty("user.dir") + "/resources/images/" + SAMPLE_DOCUMENT_FILE_NAME);
Utils.Log("file exists: " + file.exists());
String imagePath = file.getAbsolutePath();
WebElement input = driver.findElement(By.name("file"));
input.sendKeys(imagePath);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With