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:
- How to capture the screenshot of a specific element rather than entire page using Selenium Webdriver?
- WebDriver API - Selenium python binding 2 documentation - get_screenshot_as_base64
- screenshot() element method – Selenium Python
- Image Comparison Features
- Convert base64 string to Image in Python
- How to convert strings to bytes in Python
- W3CWorking Draft - Take Element Screenshot