Java 使用selenium 3 webdriver捕获网页内容的全屏快照

Java 使用selenium 3 webdriver捕获网页内容的全屏快照,java,selenium,firefox,webdriver,Java,Selenium,Firefox,Webdriver,我正在尝试拍摄网页的完整内容屏幕截图。但我只得到以下代码的基于视图的屏幕截图。浏览器是firefox,我正在使用Selenium3Web驱动程序 File scrFile5 = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); try { FileUtils.copyFile(scrFile5, new File("C:\\test.jpg"));

我正在尝试拍摄网页的完整内容屏幕截图。但我只得到以下代码的基于视图的屏幕截图。浏览器是firefox,我正在使用Selenium3Web驱动程序

File scrFile5 = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
            try {

                FileUtils.copyFile(scrFile5, new File("C:\\test.jpg"));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 

我怎样才能达到同样的效果

您可能需要使用RemoteWebDriver接口。你是在使用Firefox还是IE?见下文

File screenshotFile = null;
            try {
                // This checks to make sure we're not running an
                // incompatible driver to take a screenshot (e.g.
                // screenshots are not supported by the HtmlUnitDriver)

                //the following line will throw a ClassCastException if the current driver is not a browser typed driver
                RemoteWebDriver compatibleDriver = (RemoteWebDriver) driver;

                screenshotFile = ((TakesScreenshot) compatibleDriver).getScreenshotAs(OutputType.FILE);
            } catch (ClassCastException e) {
                //this driver does not support screenshots.
                // this should get logged as a warning -- this only means the driver cannot be of type RemoteWebDriver

            } finally {
                if (screenshotFile == null) {
                    System.out.println("This WebDriver does not support screenshots");
                    return;  //get us outa here
                }
            }

            try {

                String pathString = "some path of your choice"
                File path = new File(pathString);

                if (!path.exists())
                    path.mkdirs();

                stringPath.concat("/someFileName.png");

                File newFileLocation = new File(pathString);
                System.out.println("Full path to screenshot: " + newFileLocation.getAbsolutePath());

                FileUtils.copyFile(screenshotFile, newFileLocation);
            } catch (IOException e) {
                e.printStackTrace();
            }

这是Selenium浏览器驱动程序的老问题

试试这个工具:aShot


您可以在

找到它,我们只能对网页的可见部分进行截屏,但我们没有任何选项可以通过向下/向上滚动来对整个网页进行截屏,甚至无法通过PrintScreen/SysRqthanks获得您的回复,但如果fire fox使用selenium ide,我将设法对整个内容进行截屏。但无法通过java代码实现,我使用的是SELENIUM 3,浏览器是firefox。您是否有任何特定于firefox的代码片段会有所帮助。ThanksI已经尝试了上面的代码,它按照视图截屏,没有捕获我使用selenium ide for firefox能够实现的全部内容,所以当我尝试使用webdriver实现同样的功能时,我面临的问题。