.
Uploading a file Using Selenium Web
Driver- Handing Upload in Selenium web driver
In Selenium webdriver we can upload a file by using sendkey method. In selenium webdriver we can upload a file with other options as well.
- Sendkeys();
- Robot Class
- AutoIT tool
- Jacob API
Sendkeys();
By using the Sendkeys() method we can
upload a file in Selenium WebDrive using Java. The Sendkeys method is the most frequent and simple method to upload a file using Selenium webdriver.
Syntax-
The Basic Syntax for Upload files in
Selenium are given below.
driver.get("http://demo.guru99.com/test/upload ");
driver.findElement(By.name("uploadfile_0")).sendKeys("C:\\Users\\user1\\Desktop\\New
folder");
driver.findElement(By.name("Submit")).click();
Selenium Code for Uploading a file using
Java
package automationtesting;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import
org.openqa.selenium.chrome.ChromeDriver;
public class UploadFile {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","D:\\Sandeep\\Soft\\chromedriver.exe");
WebDriver driver= new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://demo.guru99.com/test/upload
");
//Upload
a file
driver.findElement(By.name("uploadfile_0")).sendKeys("C:\\Users\\user1\\Desktop\\New
folder");
}
}
Hope !!! The above tutorial on how to upload files in Selenium Webdriver is helpful for you ...
Team,
QA acharya
0 Comments