w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
selenium upload file java ChromeDriver/FirefoxDriver

A "*.jpeg"-File isn't a valid .jpg file.

Can you show at least the html-Code of the fileUpload?

Are you sure your JVM has access to the file? Maybe you should add the file to your resources-folder. If your file is stored in "[...]workspaceprojcetnamesrc est esources" this should work:

String pathToUpload = "/Lighthouse.jpg";
URL url = MYCLASSNAME.class.getResource(pathToUpload);
String filePath = url.getFile();
System.out.print(filePath);
File imgToUpload = new File(filePath);
String absolutePath = imgToUpload.getAbsolutePath();
System.out.print(absolutePath);
driver.findElement(By.xpath("//input[@id='FakeInputName2']")).sendKeys(absolutePath);
System.out.print(driver.getPageSource());

Be careful: 'Myclass' has to be replaced with your current classname.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.