
.
Uploading a file Using Selenium Web
Driver- Handing Upload in Selenium webdriver
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 Sendkeys() method we can
upload a file in Selenium WebDrive using java. Sendkeys method is the most frequently and simple method to upload a file using selenium webdriver.
Syntax-
The Basic Syntax for Upload file 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 !!! Above tutorial on how to upload file in selenium webdriver is helpful for you ...
Team,
QA acharya
Tags: Upload file in selenium, uploading a file using selenium , Handling Upload in selenium webdriver.
1 Comments
nice post.
ReplyDeletebest selenium online training
online training for selenium