elads11
elads11

Reputation: 377

Take a screenshot of the entire web element even when it's not visible

I have in my website, a web element that is scrollable, and in my project I take screenshots of web elements for a later use. However, in this case, you need to scroll down the webpage to see the whole element, so the regular screenshot of the specific element doesn't capture the full element. Is there a way to do it? I'm running with headless chrome, and tried somehow using Ashot dependency. The limitations I have: Has to be one screenshot. Using Maven, TestNG. Code snippet:

byte[] imageResult = webElement.getScreenshotAs(OutputType.BYTES);

Upvotes: 1

Views: 422

Answers (1)

Tal Angel
Tal Angel

Reputation: 1782

Why don't you scroll to the element or click on it before you take the screenshot?

WebElement element = driver.findElement(By.id("id_of_element"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);

If the element is bigger the the main page - you should be able to get all of it.

Upvotes: 1

Related Questions