1

When using a website and capturing pictures of specific elements on screen, Sometimes we encounter a problem in which the element is not captured in its fullest form. After investigating the issue I understand it happens when the Chrome browser opens on laptop screen, which is smaller and that's why the elements are not shown completely. How can I solve this issue? It also happens on Jenkins sometimes, how is that?

Here is my code snippet:

    byte[] imageResult = element.getScreenshotAs(OutputType.BYTES);
    BufferedImage imageSnapshot = ImageIO.read(new ByteArrayInputStream(imageResult));

 
123josh123
  • 147
  • 9
  • You may try adjusting your screen resolution to fit the application in window. This could work. But Ideally, the application should be responsive, i;e., it should auto-adjust according to the screen-size – Anand Gautam Aug 17 '22 at 12:02
  • The problem is that, the specific element for example is long, so need to scroll down even on regular sized monitor. So in this case, the element is not being captured to its fullest form – 123josh123 Aug 17 '22 at 12:18
  • 1
    Maybe try to scroll to the element via `moveToElement()` (https://stackoverflow.com/a/27386399/9741277) – leun4m Aug 17 '22 at 12:22
  • Yea that's what I'm trying, hope that it will help capture the whole element – 123josh123 Aug 17 '22 at 13:44
  • Try checking this post out: https://stackoverflow.com/questions/3401343/scroll-element-into-view-with-selenium – DeltaRage Aug 17 '22 at 14:11

1 Answers1

1

You can increase the Set the Browser resolution to bigger size and pass it in chrome options. that wil increase the browser window size and then scrollinto that element and continue with it.

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--window-size=1920,1200");
    WebDriver driver = new ChromeDriver(options);
Rakesh
  • 118
  • 1
  • 9
  • The problem I'm facing right now, is that the element is long and needs to scroll down the page for it to be seen, so event on regular sized monitor it's a problem – 123josh123 Aug 21 '22 at 14:57