繁体   English   中英

如何使用 selenium java 进行彩色截图

[英]how to take color screenshot using selenium java

屏幕截图如下图所示,但我想在实际 colors 中捕获它,我也不知道它背后的原因,谁能告诉我为什么会这样?

 ((JavascriptExecutor)driver).executeScript("window.scrollBy(0,131)");
 int yPosition = Decision_Maker.getLocation().getY();
 for(int j = 1; j<=list.size(); j++)
 {
            // Get entire page screenshot
            File screenshots = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
            BufferedImage  fullImg = ImageIO.read(screenshots);
            ImageIO.read(screenshots).getHeight();
            // Get width and height of the element
            int eleWidth =  Decision_Maker.getSize().getWidth();
            int eleHeight = Decision_Maker.getSize().getHeight();
            //Crop the entire page screenshot to get only element screenshot
            BufferedImage eleScreenshot= fullImg.getSubimage(465, 190,eleWidth,eleHeight);
            ImageIO.write(eleScreenshot, "jpg", screenshots);

                //Scroll vertically to the element
                JavascriptExecutor js = (JavascriptExecutor) driver;
                js.executeScript("window.scroll (0, " + yPosition + ") ");
               
                yPosition = yPosition + eleHeight;  
                //wait for sometime
                Thread.sleep(3000);
                
                //File Location
                String location = "E:\\Automation\\Screenshots\\";              
                Thread.sleep(3000);
                    
                //capture screenshot
                FileUtils.copyFile(screenshots, new File (location + "img" + i + ".jpg"));
                Thread.sleep(3000L);
             }
            

在此处输入图像描述

您可以创建 utils class 来截取屏幕截图并使用它

  public static void TakeScreenshot(String filename) throws IOException
{
    File file= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(file, new File("path to store screenshot" + filename + ".jpg"));
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM