0

With the below code i try to capture the screenshot of WebElement with selenium webdriver.

    WebElement ele1 = driver.findElement(By.xpath("//*[@id='main']/div[2]/div/div[2]")); 
        File screenshot1 = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        BufferedImage  fullImg1 = ImageIO.read(screenshot1);
         Point point1 = ele1.getLocation();
         int eleWidth1 = ele1.getSize().getWidth();
         int eleHeight1 = ele1.getSize().getHeight();
         BufferedImage eleScreenshot1= fullImg1.getSubimage(point1.getX(),  point1.getY(), eleWidth1,
                    eleHeight1);
         ImageIO.write(eleScreenshot1, "png", screenshot1);
         File screenshotLocation1 = new File("D:/personalloan.png");
         FileUtils.copyFile(screenshot1, screens

hotLocation1);

But, this gives the error

(y + height) is outside of Raster

Eliyas
  • 177
  • 1
  • 11

1 Answers1

0

i face this kind of problem while i used appium. There, i need to rotate the element. but when i use this code, it will take screenshot of element which will not rotated and this problem occurs. so i fixed the problem by telling appium to always open image in landscape mode.

i think some thing like this is happening also in u. when u inspect manually, it is in a form but when code works it is in different form.

so please check ur element y co ordinate properly.

noor
  • 2,954
  • 2
  • 16
  • 29