首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ashot - element屏幕截图不正确

Ashot - element屏幕截图不正确
EN

Stack Overflow用户
提问于 2020-06-22 19:46:11
回答 1查看 200关注 0票数 0

我正在尝试使用Ashot拍摄特定元素的屏幕截图。不幸的是,我没有得到元素屏幕截图。当我将我的代码发送给运行它的其他人时,元素屏幕截图是正确的。我不明白为什么它不能在我的电脑上工作。

代码是:

代码语言:javascript
复制
public class ScreenShot
{
    WebDriver driver;

    @BeforeClass
    public void StartSession()
    {
        WebDriverManager.chromedriver().setup();
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("https://www.google.com/");
    }

    @Test
    public void VerifyScreenShot()
    {
        TakeScreenShot();
        //CompareScreenShot();
    }

    @Step("take element screen shot")
    public void TakeScreenShot()
    {
        try
        {
            //find the element you want to picture
            WebElement imageElement = driver.findElement(By.id("hplogo"));
            //take the element screenshot
            Screenshot imageScreenShot = new AShot().coordsProvider(new WebDriverCoordsProvider()).takeScreenshot(driver,imageElement);
            //save the element picture in the project folder under img folder
            ImageIO.write(imageScreenShot.getImage(),"png",new File("./img/glogo.png"));
        }
        catch (Exception e)
        {
            System.out.println("Error writing image file: "+ e);
        }
    }

    @AfterClass
    public void EndSession()
    {
        driver.quit();
    }

}
EN

回答 1

Stack Overflow用户

发布于 2020-06-24 14:17:44

我找到了解决方案。我需要将计算机分辨率更改为100%,然后拍摄元素屏幕截图。元素图像和我预期的一样。

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

https://stackoverflow.com/questions/62513682

复制
相关文章

相似问题

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