
- 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 does selenium webdriver upload files to the browser?
We can upload files to the browser with the help of Selenium webdriver. This is done with the help of sendKeys() method on the element which does the selection of the file by specifying the path of the file to be uploaded.
While working on file upload functionality, we need to click on the Browse button. This is taken care of by webdriver for elements with attribute type having value as file. Also, the path of the file to be uploaded should be correct.
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 FileUpld{ 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.xpath("//input[@name='photo']")); // file selection field with file path l.sendKeys("C:\\Users\\ghs6kor\\Pictures\\Tulips.jpg"); driver.quit(); } }
Output
- Related Questions & Answers
- How to upload files using Selenium Webdriver?
- How does the Selenium WebDriver work?
- How to handle windows file upload using Selenium WebDriver?
- How to launch Edge browser with Selenium Webdriver?
- How does selenium interact with the Web browser?
- Does Selenium support Safari browser?
- How to maximize the browser window in Selenium WebDriver using C#?
- File Upload using Selenium WebDriver and Java Robot Class.
- How to connect to an already open browser using Selenium Webdriver?
- Does Selenium support headless browser testing?
- Using the Selenium WebDriver - Unable to launch chrome browser on Mac
- Capturing browser logs with Selenium WebDriver using Java.
- Clear browser Cookies with Selenium WebDriver Java bindings.
- How to close child browser window in Selenium WebDriver using Java?
- How does Selenium Webdriver handle the SSL certificate in Safari?
Advertisements