Tuesday, April 17, 2012

write the selenium output result into a document instead of console


If you want to display all the links into a text file or word document then you can do as follows
1. We have getAllLinks() in selenium which will prints all links to the console output.
     
     selenium.getAllLinks();

2. Instantiate FileWriter and BufferedWriter from java.io package.
4. If need to write the output into a text file then store all links into an String array as follows

     
 String alllinks [] = selenium.getAllLinks();

5. Use "for loop" to write the values into file with help of BufferedWriter object.


System.out.println("Get All Links");
String alllinks [] = selenium.getAllLinks();

FileWriter fileWriter2 = new FileWriter("D:\\allLinks.doc");
BufferedWriter bufferedWriter2 = new BufferedWriter(fileWriter2);
bufferedWriter2.write("Get All Links");
for(int c=0; c<alllinks.length; c++){

        bufferedWriter2.write(alllinks[c]);
        bufferedWriter2.newLine();
    System.out.println("\n");
} bufferedWriter2.close();


No comments:

Post a Comment