Professional Documents
Culture Documents
edureka
We often come across scenarios while testing where we have to upload a le. For di erent UI there are di erent ways to upload
a le. Following pointers will be covered in this Uploading a FIle using Selenium article:
Before diving into further details let’s take an example and learn how we can upload a le while automating our scripts using
Selenium.
Choose File Button: On clicking this button we can choose the le we wish to upload from our machine.
Input type: The Input type of the Choose File button in the above image is of le type.
Note: I would be using an example of edureka where we can upload our image by editing personal details. For this, I need to
rst login using edureka account. To login, I will be using my username and password, I request you to use yours to practice for
the same.
Example
System.setProperty(“webdriver.chrome.driver”,”/Users/ankita/Downloads/chromedriver”);
Example:
WebDriver driver = new ChromeDriver(options);
Navigate to the Edureka main page and then Login using your username and password
Example:
1 driver.get("<a href="https://www.edureka.co/">https://www.edureka.co/</a>");
2 driver.findElement(By.linkText("Log In")).click();
3 driver.findElement(By.id("si_popup_email")).sendKeys("username");
4 driver.findElement(By.id("si_popup_passwd")).sendKeys("password");
5 driver.findElement(By.xpath("//*[@id=\"new_sign_up_mode\"]/div/div/div[2]/div[3]/form/button")).click
After you Login into Edureka account using your username and password. Navigate to page where you can upload your
image by editing your personal details.
Here, I am navigating right away to the page from where by pressing image icon I will be navigated to the page to upload
image.
On clicking on the highlighted icon above, you will be navigated to the image upload page.
1 driver.get("<a href="https://learning.edureka.co/onboarding/personaldetails">https://learning.edureka
2 driver.findElement(By.xpath("//*[@id=\"collapseOne\"]/div/div/div[2]/a/i")).click();
As soon as you click on the above mentioned icon, you will be navigated to the page where you can upload the image(as
seen below).
FREE WEBINAR
CERTIFICATION
TRAINING TESTING USING
APPIUM TESTING USING
JMETER CERTIFICATI
TRAINING
Selenium Certi cation Mobile App Testing Using Performance Testing Manual Testing
Training Appium Using JMeter Certi cation Trainin
Now, without clicking the Choose File button we will use Sendkeys to send the absolute path of the image le which we
would like to upload.
Example:
NOTE: If you click on the choose le button, then you will be taken to your machine window to select a le and then you will not
be able to select a le using selenium. Hence, you will have to take the help of third tool i.e. either AutoIT or Sikuli.
We will be discussing about them in detail in our other tutorials.
After you pass the absolute path of the le with sendkeys, the upload button will be enabled and the image selected will be
seen as below:
FREE WEBINAR
Example:
driver. ndElement(By.cssSelector(“div[class=’submitbtnsec’] > button[type=’submit’]”)).click();
With this uploading of le is done and now the new uploaded image will be seen in your personal details.
Below is the script to perform the above-mentioned steps in Selenium using Java
FREE WEBINAR
1 import java.util.concurrent.TimeUnit;
2 import org.openqa.selenium.By;
3 import org.openqa.selenium.WebDriver;
4 import org.openqa.selenium.WebElement;
5
6
import
import
org.openqa.selenium.chrome.ChromeDriver;
Subscribe to our Newsletter, and get personalized recommendations.
org.openqa.selenium.chrome.ChromeOptions;
×
7 import org.openqa.selenium.support.ui.ExpectedConditions;
8 import org.openqa.selenium.support.ui.WebDriverWait;
9 Sign up with Google
10 public class EdurekaUploadTest {
11
12 public static void main(String[] args) throws InterruptedException {
Signup with Facebook
13
14 System.setProperty("webdriver.chrome.driver","/Users/ankita/Downloads/chromedriver");
15 WebDriver driver = new ChromeDriver(options);
16 Already have an account? Sign in.
driver.get("<a href="https://www.edureka.co/">https://www.edureka.co/</a>");
17
18 WebDriverWait wait = new WebDriverWait(driver, 10);
19 wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.linkText("Log In"))));
20 driver.findElement(By.linkText("Log In")).click();
21 driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
22 wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("si_popup_email"))));
23 driver.findElement(By.id("si_popup_email")).sendKeys("username");
24 driver.findElement(By.id("si_popup_passwd")).sendKeys("password");
25
26 driver.findElement(By.xpath("//*[@id=\"new_sign_up_mode\"]/div/div/div[2]/div[3]/form/button")).click
27
28 Thread.sleep(2000);
29 driver.get("<a href="https://learning.edureka.co/onboarding/personaldetails">https://learning.edureka
30 Thread.sleep(1000);
31
32 WebElement imageEdit = driver.findElement(By.xpath("//*[@id=\"collapseOne\"]/div/div/div[2]/a/i"));
33
34 imageEdit.click();
35 Thread.sleep(1000);
36 WebElement chooseFile = driver.findElement(By.id("custom-input"));
37 chooseFile.sendKeys("/Users/ankita/Downloads/edureka.png");
38 Thread.sleep(1000);
39 driver.findElement(By.cssSelector("div[class='submitbtnsec'] > button[type='submit']")).click();
40
41 }
42
43 }
With this, we come to an end of this Uploading a File Using Selenium article. In this tutorial, we have learned about how to
upload a le using “Sendkeys” in selenium. The major drawback with this approach is that we can use sendkeys only when the
type of the input is of le type or there is an editable text box along with the browse button. In such a case, we can give the
absolute path of the le instead of clicking the button provided to choose a le from the machine.
If you wish to learn Selenium and build a career in the testing domain, then check out our interactive, live-online Selenium 3.0
Certi cation Training here, that comes with 24*7 support to guide you throughout your learning period.
Selenium WebDriver Tutorial – Why Use Selenium with $3 Automate Web Apps Testing Selenium Tutorial –
Get Started With Selenium Million Bugs? With Selenium Webdriver Complete Tutorial o
WebDriver Selenium Automatio
‹›
FREE WEBINAR
Arti cial Intelligence BI and Visualization Big Data Blockchain Cloud Computing Cyber Security Data Science
Data Warehousing and ETL Databases DevOps Digital Marketing Front End Web Development Mobile Development
Already have an account? Sign in.
TRENDING CERTIFICATION COURSES TRENDING MASTERS COURSES
Big Data Hadoop Certi cation Training Cloud Architect Masters Program
Tableau Training & Certi cation Big Data Architect Masters Program
Python Certi cation Training for Data Science Machine Learning Engineer Masters Program
Selenium Certi cation Training Full Stack Web Developer Masters Program
Robotic Process Automation Training using UiPath Data Analyst Masters Program
Apache Spark and Scala Certi cation Training Test Automation Engineer Masters Program
Microsoft Power BI Training Post-Graduate Program in Arti cial Intelligence & Machine Learning
Online Java Course and Training Post-Graduate Program in Big Data Engineering
About us Careers
Community
DOWNLOAD APP
Sitemap
Blog Sitemap
Community Sitemap
Webinars
CATEGORIES
CATEGORIES
Cloud Computing DevOps Big Data Data Science BI and Visualization Programming & Frameworks Software Testing
Project Management and Methodologies Robotic Process Automation Frontend Development Data Warehousing and ETL Arti cial Intelligence Blockchain
Databases Cyber Security Mobile Development Operating Systems Architecture & Design Patterns Digital Marketing
Spring tutorial PHP interview questions Inheritance in Java Polymorphism in Java Spring interview questions Pointers in C Linux commands
Android tutorial JavaScript tutorial jQuery tutorial SQL interview questions MySQL tutorial Machine learning tutorial Python tutorial
What is machine learning Ethical hacking tutorial SQL injection AWS certi cation career opportunities AWS tutorial What Is cloud computing
What is blockchain Hadoop tutorial What is arti cial intelligence Node Tutorial Collections in Java Exception handling in java
Python Programming Language Python interview questions Multithreading in Java ReactJS Tutorial Data Science vs Big Data vs Data Analy…
Software Testing Interview Questions R Tutorial Java Programs JavaScript Reserved Words and Keywords Implement thread.yield() in Java: Examp…
Implement Optical Character Recogniti… All you Need to Know About Implement…
FREE WEBINAR
Selenium
XPath Tutorial For Beginn…
https://www.edureka.co/blog/uploading-file-usiing-selenium/ 7/8
6/16/2020 A Step by Step Guide to Uploading a file using Selenium | Edureka
© 2020 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved. Terms & Conditions
FREE WEBINAR
‹›
Comments 0 Comments
ALSO ON HTTPS://WWW.EDUREKA.CO/BLOG/
7 months ago • 1 comment 5 months ago • 3 comments 4 months ago • 1 comment 7 mont
This article on How to In the world of smartphones This article talks about how The Ed
become a Digital Marketer and Artificial Intelligence, it you can incorporate is on B
will help you understand … is quite important to … Bootstrap functionality … is a ste
LOG IN WITH
OR SIGN UP WITH DISQUS ?
Name
SELENIUM
CERTIFICATION TRAINING
Selenium Certi cation Mobile App Testing Using Performance Testing Using Manual Testing C
Training Appium JMeter Training
26k Enrolled Learners 2k Enrolled Learners 2k Enrolled Learners 5k Enrolled Learners
Weekend/Weekday Weekend Weekend Weekend
Live Class Live Class Live Class Live Class