Take Multiple Screenshot
Navigate to
each link of a web page and take screenshot of all the pages
package pack5;
import
java.io.File;
import java.io.IOException;
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.WebElement;
import
org.openqa.selenium.firefox.FirefoxDriver;
public class MultipleScreenshots
{
              public static void
main(String[] args) throws
IOException {
                             // TODO
Auto-generated method stub
                             FirefoxDriver driver = new FirefoxDriver();
                             driver.manage().window().maximize();
                             driver.get("http://newtours.demoaut.com/");
                             List<WebElement> links = driver.findElements(By.tagName("a"));
                             System.out.println(links.size());
                             for(int i=0;i<links.size();i++)
                             {
                                           if(!links.get(i).getText().isEmpty())
                                           {
                                                          System.out.println(links.get(i).getText());
                                                          String linkname = links.get(i).getText();
                                                          links.get(i).click();
                                                          File scrFile =
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
                                                          FileUtils.copyFile(scrFile, new File("D:\\Selenium\\"+linkname+".png"));
                                                          driver.navigate().back();
                                                         links=driver.findElements(By.tagName("a"));
                                           }
                             }
              }
}
 
No comments:
Post a Comment