How to upload a file in Selenium with no text box?

We can upload a file in Selenium with no text box. This is achieved with the help of the sendKeys method. It is applied on the web element which performs the task of selecting the path of the file to be uploaded.

As we make an attempt to upload, we shall click on the Browse button. If we investigate the HTML code for this, we shall be able to locate the attribute type having the value file. Moreover, the file path to be uploaded should be accurate.


Code Implementation.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import java.util.concurrent.TimeUnit;
public class FileUpload{
   public static void main(String[] args) {
      WebDriver driver = new ChromeDriver();
      String u = "";
      driver.manage().timeouts().implicitlyWait(6, TimeUnit.SECONDS);
      // identify element
      WebElement m=driver.findElement(By.xpath("//input[@name='photo']"));
      // file selection field with file path