简体   繁体   English

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

[英]how to take color screenshot using selenium java

screenshots is getting captured like below images but i want to capture it in actual colors also i don't know the reason behind it can anybody tell me why this is happening?屏幕截图如下图所示,但我想在实际 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);
             }
            

在此处输入图像描述

You can create utils class to take screenshot and use it您可以创建 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.

相关问题 如何在firefox无头(java中的selenium)中截取屏幕截图? - How to take a screenshot in firefox headless (selenium in java)? 无法使用HtmlUnitDriver进行screenShot [Selenium WebDriver java] - Not able to take screenShot using HtmlUnitDriver [Selenium WebDriver java] 为什么我不能在Java中使用Selenium Webdriver截屏? - Why I can't take a screenshot using selenium webdriver in java? 如何使用带有 Java 的 Selenium WebDriver 获取可滚动网页的整页屏幕截图? - How to take full page Screenshot of a scrollable webpage using Selenium WebDriver with Java? 如何通过 Selenium 和 Java 使用 AShot 库截取整页截图 - How to take full page screenshot using AShot library through Selenium and Java 如何使用IP地址在Java中拍摄屏幕截图 - How to take Screenshot in Java using IP address 如何获取截图然后点击selenium中保存的截图? - How to take screenshot and then click on that saved screenshot in selenium? 每次与页面交互后如何截屏? Java, Selenium - How to take screenshot after every interaction with page? Java, Selenium 如何在Selenium Webdriver中使用Robot Framework截屏 - How to Take screenshot using Robot Framework in selenium webdriver 如何使用ReportNG在Selenium WebDriver中拍摄失败的测试的屏幕截图 - How to take screenshot of failed test in selenium webdriver using ReportNG
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM