- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 files using Selenium Webdriver?
We can upload files using Selenium Webdriver. This is achieved by the sendKeys method. We have to first identify the element which performs the file selection by mentioning the file path [to be uploaded].
This is only applied to an element having a type attribute set to file as a value along with the element tag name as input. The below html code shows the element with type = file value set.
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 WndsFileUpl{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); //implicit wait driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); //launch application driver.get("https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm"); // identify element WebElement m=driver.findElement(By.xpath("//input[@type='file']")); // windows file upload with file path m.sendKeys("C:\Users\Pictures\Logo.jpg"); //browser close driver.close(); } }
Output
- Related Articles
- How does selenium webdriver upload files to the browser?
- How to handle windows file upload using Selenium WebDriver?
- File Upload using Selenium WebDriver and Java Robot Class.
- How to use chrome webdriver in Selenium to download files in Python?
- How to Verify Tooltip using Selenium WebDriver?
- How to select checkboxes using selenium java webdriver?
- How to deal with ModalDialog using selenium webdriver?
- How to upload file with selenium (Python)?
- How to handle frame in Selenium WebDriver using java?
- How to click on across browsers using Selenium Webdriver?
- How to scroll down using Selenium WebDriver with Java?
- How to check URL for 404 using Selenium WebDriver?
- How to get HTTP Response Code using Selenium WebDriver?
- How to use clickandwait in Selenium Webdriver using Java?
- How to open a new tab using Selenium WebDriver?

Advertisements