Automation Using Selenium Webdriver

Thursday, 29 September 2016

How to take screen shots of all page links in web site Automatically

How to take screen shots of all page links in web site Automatically


How to take screen shots of all page links in a web site automatically in Chrome driver using Selenium Web Driver.

Below Example Best Check it and Execute Programme   

package ScreenShot;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;


public class LinksScreenshot 
   {
//TestCase id:1 Step1:Decp
//TestCase id:1 Step2:Launch Chrome
//TestCase id:1 Step3:Navigate to newtours.demoaut
//TestCase id:1 Step4:Capture all links
//TestCase id:1 Step5:click on the all links and take screen shots
//Test Case id:1 Step6:close the browser

public static void main(String[] arg) throws IOException

{
 System.out.println("**********excution will stat wait**************");

 System.setProperty("webdriver.chrome.driver",  "C:\\chromedriver.exe");
 WebDriver driver=new ChromeDriver();
         driver.get("http://newtours.demoaut.com/");
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
       List<WebElement> links=driver.findElements(By.tagName("a"));
        System.out.println("no of links:" +links.size());

      for(int i=0;i<links.size();i++)
      {
          if((links.get(i).isDisplayed()))
          {
          String linkname=links.get(i).getText();
                 links.get(i).click();
                
             File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(scrFile, new File("E:\\Jagan\\ScreenShot"+linkname+"png"));
   

          driver.navigate().back();
         

          links=driver.findElements(By.tagName("a"));
          
          }     
         
      }
      driver.close();
 }
        
          }       
      

      //OutPut:No of Links:16 We did get
 
 


  

1 comment:

  1. Hello Jaganmohan,

    Nice set of information man!! Your example provided here looks simple and matured. Good in providing such a detailed stuff, Here I like to suggest something useful for your viewers about ISTQB Certification ==> Selenium Certification in Chennai ==>Next Batch Details Selenium Training Details

    ReplyDelete