- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
- Related Articles
- How to upload file with selenium (Python)?
- How to read a text file in Selenium with python?
- How to write a text file in Selenium with python?
- How to handle windows file upload using Selenium WebDriver?
- How to create a file upload button with HTML?
- How to upload a file in Cypress?
- How to key in values in input text box with Javascript executor in Selenium with python?
- How to upload a file using JSP?
- File Upload using Selenium WebDriver and Java Robot Class.
- How to input text in the text box without calling the sendKeys() using Selenium?
- How do you enter text in the edit box in Selenium?
- How to upload files using Selenium Webdriver?
- Upload file with php to another php server
- How to work with a text file in Python?
- How to read a text file with C++?

Advertisements