[英]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.