簡體   English   中英

Ashot - 未正確拍攝元素屏幕截圖

[英]Ashot - element screenshot is not taken correcly

我正在嘗試使用 Ashot 截取特定元素的屏幕截圖。 不幸的是,我沒有得到元素截圖。 當我將代碼發送給運行它的其他人時,元素屏幕截圖被正確拍攝。 我不明白為什么它不能在我的電腦上運行。

代碼是:

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();
    }

}

我找到了解決方案。 我需要將我的計算機分辨率更改為 100%,而不是截取元素屏幕截圖。 比元素圖像如我所料。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM