Search On Google

Tuesday, February 19, 2019

selenium upload file example

How to upload and download file by selenium?
For file upload with selenium you have to get id of select file elelement
and then you should sendKeys option to set file path .
That’s all to select file with selenium and then apply appropriate programming to send data to server
to upload your file.

Example to file selection:-
        myElement1.sendKeys("C:\\Users\\Desk-105\\Documents\\one.txt");

"package pkg1;

Example for upload file in selenium:-

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class MyClass911_upload_file { 
    public static void main(String[] args) {       
   
        System.setProperty(""webdriver.chrome.driver"",""C:\\Users\\Desk-105\\Documents\\SELENIUM\\chromedriver.exe"");   
        WebDriver driver = new ChromeDriver();   

        driver.get("https://www.onlinetutorial.info/p/selenium-upload-file.html");
        WebElement myElement1 =driver.findElement(By.id(""upload_file_1""));
        myElement1.sendKeys(""C:\\Users\\Desk-105\\Documents\\one.txt"");
        driver.findElement(By.id(""upload_file_button"")).click();
     
    }
}
"

No comments:

Post a Comment

About Me

My photo
Mumbai, Maharashtra, India