How to capture a specific element's screenshot with Appium?

This article will explain and share how to capture a specific element screenshot on Simulator.

I will use the Apple News App as an example to explain how to do it.

The Today tab icon is selected, so it is red color, and the other News+, Following, and Search icons are gray color on the simulator. 

You can see the simulator screenshot below:

First, You need to find the element of the Today tab icon, so code like this:

    today_element = (AppiumBy.ACCESSIBILITY_ID, 'Today')
    today_element.screenshot_as_base64 # type is String

Then you just need to get the elements whose icons are selected and unselected. 

You can see the difference in the screenshot below:


If you want to check the element of the screenshot with the image, you can use:

    today_element.screenshot('today.png') 


I hope it can help you :) 

If you want me translate to Chinese you can leave a comment below to let me know plz!!

Reference:

張貼留言

較新的 較舊