Tuesday, August 15, 2017

How to take screenshot of WebElemets in Selenium?

In the previous post AShot() in Selenium 3 for taking full page screenshot? we have seen how to capture the full page screenshot in Selenium using AShot() utility. Now we will see how to capture the screenshot of WebElement using AShot().

Syntax: The below method is used to capture the screenshot of the web element.
  • We need to pass two arguments to the above method, one is WebDriver object and another is web element . 
aShot will find element's size and position and crop original image. WebDriver API provides a method to find the WebElement's coordinates  but different WebDriver implementations behave differently.

Step 1: Download AShot() and Selenium Standalone. Add this two jar files to the project.
Step 2: The below sample test launches Selenium Babu blog and captures the screenshots of  Total Pageviews and Title Logo.
Step 3: Checkout the below video for better understanding.

No comments:

Post a Comment

Selenium4: Working with two parallel windows in Selenium Automation

A new method newWindow() is introduced in Selenium 4 (Alpha). Using this method we can open a new tab or new window from the current window...