uploading a file in Selenium Web
Driver
Sendkeys();
By Using Sendkeys() method we can
upload a file in Selenium
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 upload 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");
}
}
nice post.
ReplyDeletebest selenium online training
online training for selenium