Monday 14 November 2016

Open a file in selenium webdriver

Hi,

Today we all be learning that how we can read a file in selenium webdriver.We can read the content of a file using java build in classes.we will be not using any selenium command for reading a file in webdriver.Java has build in classes for reading a file such as 


  • FileReader
  • BufferedReader
These two are the main function that are used to read a file and read its content.It is a java build in function we are not using any selenium specific function.


SCRIPT FOR READING A FILE IN WEBDRIVER

mport java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import org.openqa.selenium.NoSuchElementException;


public class Readfile{
 public static void main(String[] args)  
 {
  String path = "D:\\test.txt"; 
  
  FileReader file = null;

  BufferedReader read  = null;
  try{
     String sCurrentLine;
     file =  new FileReader(path);
     read = new BufferedReader(file);
     while ((sCurrentLine = read.readLine()) != null)
     {
    System.out.println(sCurrentLine);
     }
 }catch(IOException e)
 {
System.out.println(e.getMessage());
 }


how to use a file in selenium

how to open a file in selenium


0 comments: