Upload file in selenium
This is the most frequent question how to upload file in selenium that we always have in selenium webdriver to upload files in upload section of a web page or a web form.We have mainly 2 method that we can use to upload file in web page.One method is Upload file in selenium webdriver using sendkeys and other is upload file in selenium webdriver using autoit.
How to upload a file using selenium webdriver in java
We will see how we can upload file in selenium webdriver using sendkeys.This is the most frequently used technique to upload file using sendkeys().This is the inbuild selenium method to send key values to textbox but here we will see how we can use this method to upload files in the upload element or upload section or browse button.
{ public void Upload_document_in_Selenium(String filepath)
{
delay(3);
int in=filepath.indexOf(".");
FilePaths=filepath.substring(0,in);
String path = System.getProperty("user.dir")+"\\TestData\\"+FilePaths;
delay(3);
UploadFile.sendKeys(path);
delay(10);
UploadButton.click();
delay(3);
clickNext.click();
}
}
Upload file in selenium webdriver using sendkeys:
Below is the generic method that we will used to upload the files by just passing the file path as a parameter to the method and this method will find the upload element in the UI and send the path of the file to upload or upload to input type file. Below is the method which will be used to upload file in selenium
public static void main(String args[])Method to upload file in selenium:
{ public void Upload_document_in_Selenium(String filepath)
{
delay(3);
int in=filepath.indexOf(".");
FilePaths=filepath.substring(0,in);
String path = System.getProperty("user.dir")+"\\TestData\\"+FilePaths;
delay(3);
UploadFile.sendKeys(path);
delay(10);
UploadButton.click();
delay(3);
clickNext.click();
}
}
0 comments: