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

Java Program 5: How to reverse given string and each word of it?

Let us understand the problem with an example, suppose "Learn Core Java" is the given string then the expected output should be &...