1

I got this error

(y + height) is outside of Raste

when I try to get a screenshot of an element that need a scroll down to see it all

if that's the problem, how I can add scroll down in this code

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

I'm using this code

static ChromeOptions options = new ChromeOptions();
static WebDriver driver = new ChromeDriver(options.setHeadless(true).addArguments("--window-size=1920,1080"));

chromedriver v2.45

phantomjs was working fine in getting screenshot of this element

the other screenshots working fine because they don't need to scroll down to see it all

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
M J
  • 174
  • 1
  • 12
  • The coordinates `x` and `y` on your html interpreted code in the browser aren't obviously the same in the `picture`. what version of selenium you are using , – Incepter Jan 31 '19 at 10:04
  • i'm using selenium 3.8.1 – M J Jan 31 '19 at 10:11
  • Can you please add some sysout to print x y and element width and height ? plus the fullImg specs (width and height) – Incepter Jan 31 '19 at 10:20
  • i did ```System.out.println(eleWidth); System.out.println(eleHeight); System.out.println(point.getX()); System.out.println(point.getY());``` output 860 832 520 344 – M J Jan 31 '19 at 10:27
  • please host your screenshot somewhere, i had no luck accessing your website (cookie) and the login page is only 630px height, and from your sysouts it s at least 1174 – Incepter Jan 31 '19 at 10:34
  • this is the webpage, please download it https://www.mediafire.com/file/oz2uuo3ojfte1co/webpage.zip/file – M J Jan 31 '19 at 10:43
  • also the element width and height is 832 832 – M J Jan 31 '19 at 10:44
  • Please also i need the screenshot, it will explain everything – Incepter Jan 31 '19 at 10:45
  • https://i.imgur.com/dqilqk6.png – M J Jan 31 '19 at 10:46
  • aslo use the browser inspecter+ctrl f and put the xpath to see the full element i need – M J Jan 31 '19 at 10:47
  • the weird thing that it was working fine in phantomjs – M J Jan 31 '19 at 10:47
  • I see, so my worries were right. In the versions above 3.1 of selenium, they removed the screenshot of all screen, but remained only of the viewport ([see this answer](https://stackoverflow.com/a/41630829/7104283). This was one of the main issues I didn't migrate from the 3 version to later ones. – Incepter Jan 31 '19 at 10:49
  • yes. the problem is some browsers drivers. So all i think of right now is: either you switch back to phantom. or you scrap your element and save it as html file with all the calculated css so it will appear the same . – Incepter Jan 31 '19 at 10:50
  • understood, but i switched back to selenium 2.35.0 and i still getting the same errors – M J Jan 31 '19 at 10:56
  • Did you tried using firefox ? (you ll need the 47 version with later versions of selenium, or else geko driver) – Incepter Jan 31 '19 at 10:57
  • I was using selenium `3.0.1` with firefox `47.0.1`. everything was alright – Incepter Jan 31 '19 at 10:58
  • alright, i will try and let you know, give me some minutes – M J Jan 31 '19 at 10:59
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/187646/discussion-between-mohamed-el-ayadi-and-m-j). – Incepter Jan 31 '19 at 11:00

0 Answers0