我收到此错误
(y + height) is outside of Raste
当我尝试获取需要向下滚动才能看到全部内容的元素的屏幕截图时
如果这是问题,我如何添加此代码中的向下滚动
public void getAllInfo() throws IOException {
String cookie = String.join("\n",Files.readAllLines(Paths.get("temp\\cookie.txt")));
Login webpage = new Login();
WebDriver pagee = webpage.driver;
pagee.navigate().to("https://www4.inscription.tn/ORegMx/servlet/ServletInfoEtud?action=toInfoPerson&Idsession="+cookie);
// Get entire page screenshot
WebElement taswira = driver.findElement(By.xpath("/html[1]/body[1]/table[1]/tbody[1]/tr[1]/td[1]/table[1]/tbody[1]/tr[1]/td[1]/table[2]/tbody[1]/tr[2]/td[1]/div[1]"));
File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
BufferedImage fullImg = null;
try {
fullImg = ImageIO.read(screenshot);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Get the location of element on the page
org.openqa.selenium.Point point = taswira.getLocation();
// Get width and height of the element
int eleWidth = taswira.getSize().getWidth();
int eleHeight = taswira.getSize().getHeight();
// Crop the entire page screenshot to get only element screenshot
BufferedImage eleScreenshot = fullImg.getSubimage(point.getX(), point.getY(), eleWidth, eleHeight);
try {
ImageIO.write(eleScreenshot, "png", screenshot);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// Copy the element screenshot to disk
File screenshotLocation = new File("temp\\info.png");
try {
FileUtils.copyFile(screenshot, screenshotLocation);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我正在使用此代码
static ChromeOptions options = new ChromeOptions();
static WebDriver driver = new ChromeDriver(options.setHeadless(true).addArguments("--window-size=1920,1080"));
chromedriver v2.45
phantomjs在获取此元素的屏幕截图时工作正常
其他屏幕截图效果很好,因为它们无需向下滚动即可查看全部内容