- 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 click on 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 Articles
- 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?
- How do you click on an element which is hidden using Selenium WebDriver?
- How to use Selenium webdriver to click google search?
- Selenium Webdriver submit() vs click().
- How to click on a hyper link using linkText in Selenium?
- How to create right click using selenium?
- How to click on a link in Selenium?
- How to Verify Tooltip using Selenium WebDriver?
- How to upload files using Selenium Webdriver?
- How to perform right click using Selenium ChromeDriver?
- How to install Selenium WebDriver on Mac OS?
- Delete Cookies On All Domains using Selenium Webdriver.

Advertisements