 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.

Example
Code Implementation.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class FileUpload{    public static void main(String[] args) {       System.setProperty("webdriver.chrome.driver","C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");       WebDriver driver = new ChromeDriver();       String u = "https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm";       driver.get(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       m.sendKeys("C:\Users\ghs6kor\Tulips.jpg");    } }  Output

Advertisements
 