首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >需要使用网页驱动程序拍摄www.flipkart.com的全网页屏幕截图

需要使用网页驱动程序拍摄www.flipkart.com的全网页屏幕截图
EN

Stack Overflow用户
提问于 2016-10-08 14:13:07
回答 1查看 402关注 0票数 0

我需要捕获整个网页的www.flipkart.com使用网页驱动程序。

为了同样的目的,我已经写了下面的代码。但它不起作用。请提个建议。

代码语言:javascript
复制
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;

public class ScreenShot {

    public static WebDriver driver = null;

    public static void main(String[] args) throws IOException, InterruptedException {
                System.setProperty("webdriver.gecko.driver","C:\\Eclipse\\Drivers\\geckodriver.exe");
        driver = new FirefoxDriver();
        driver.manage().window().maximize();

        driver.get("https://www.flipkart.com/");
        Thread.sleep(10000);


        //Take the screenshot of the entire home page and save it to a png file
        Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(100)).takeScreenshot(driver);

        //Screenshot screenshot = new AShot().takeScreenshot(driver, driver.findElement(By.xpath(".//*[@id='container']")));
        ImageIO.write(screenshot.getImage(), "PNG", new File("C:\\Users\\Vishvambruth JT\\Desktop\\home.png"));

        driver.quit();
    }   
}
EN

回答 1

Stack Overflow用户

发布于 2016-10-08 15:07:39

使用下面的代码尝试一次。

代码语言:javascript
复制
public class Flipcart { 
    public WebDriver d;
    Logger log;
    @Test
    public void m1() throws Exception
    {   
        try
        {
            d=new FirefoxDriver();
            d.manage().window().maximize();
            d.get("https://www.flipkart.com/");
            String pagetitle=d.getTitle();

        }
        catch(Exception e)
        {
            System.out.println("something happened, look into screenshot..");
            screenShot();
        }
    }
    public void screenShot() throws Exception
    {
        Files.deleteIfExists(Paths.get("G:\\"+"Test results.png"));
        System.out.println("previous pics deleted...");
        File scrFile = ((TakesScreenshot)d).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(scrFile,new File("G:\\"+"Test results.png"));
}

}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39929294

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档