Here’s the code sample from our tutorial on how to upload a file in Selenium for Java

 

package file_upload;
import base.BaseTests;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
public class FileUploadTests extends BaseTests {
@BeforeEach
public void launchApp(){
driver.get("https://kitchen.applitools.com/ingredients/file-picker");
}
@Test
public void testFileUpload() {
String filePath = "/Users/angie/workspace/recipes/resources/images/mac-n-cheese.jpg";
driver.findElement(By.id("photo-upload")).sendKeys(filePath);
}
}
view raw FileUploadTests.java delivered with ❤ by emgithub

View on GitHub
Angie Jones
Automation Architect

Ready for the next generation of testing?

Get started today Schedule a demo