123josh123
123josh123

Reputation: 147

Selenium can't capture the whole element because of monitor size

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

 

Upvotes: 1

Views: 1078

Answers (1)

Rakesh
Rakesh

Reputation: 171

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

Upvotes: 1

Related Questions