

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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 click on <input type=file> across browsers using Selenium Webdriver?
We can click on a button with <input type= file> across browsers with Selenium webdriver. First of all we need to identify the element with the help of locators like xpath or css, then apply sendKeys() method where the path of the file to be uploaded is passed.
Let us see the html code of an element with input type as file. The corresponding representation of the element on the screen shall be.
For working with this element we need to first interact with the Browse button and also the path of the file to be uploaded should be valid.
Example
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 TypeFile{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver","C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url ="https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm"; driver.get(url); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); // identify element WebElement l=driver.findElement(By.cssSelector("input[type='file']")); // file path passed with sendkeys() l.sendKeys("C:\\Users\\ghs6kor\\Pictures\\Desert.jpg"); driver.quit(); } }
Output
- Related Questions & Answers
- How to click Allow on Show Notifications popup using Selenium Webdriver?
- How to click on a link using Selenium webdriver in Python.
- How to click on hidden element in Selenium WebDriver?
- How to click on image in selenium webdriver Python?
- Selenium Webdriver submit() vs click().
- How do you click on an element which is hidden using Selenium WebDriver?
- How can I download a file on a click event using selenium?
- How to handle windows file upload using Selenium WebDriver?
- How to use Selenium webdriver to click google search?
- How to type in textbox using Selenium WebDriver with Java?
- How to send keyboard input to a textbox on a webpage using Python Selenium webdriver?
- How to click on a hyper link using linkText in Selenium?
- How to click on a link in Selenium?
- How to create right click using selenium?
- File Upload using Selenium WebDriver and Java Robot Class.
Advertisements