Capture Similar Elements

As an example, let’s consider the “Okay Bear” image on OpenSea as an example, which has a typical grid structure.

Okay Bear

1. Locators Capture #

Now let’s go through this use case togaether.

Step1. Click the Capture button in the VS Code plugin to start the Recorder
Step2. Click on Similar elements in the Recorder:
Step3. Ctrl + mouse click to grab the first and second elements.(1)
Step3. Ctrl + mouse click to grab the first and second elements.(2)


After crawling the locator corresponding to the similar elements, call find_elements to return a UI element list (find_element returns a single UI element.

2. Sample code: #

Get the picture URL by get_property. Download the picture using request lib, and use send_hotkey to press the PgDn key to scroll and load more picture.

import requests
from time import sleep
from clicknium import clicknium as cc, locator
def main():
cc.chrome.open("https://opensea.io/collection/okay-bears")
nftDic = {}

while True:
newDic = {}
finish = True
sleep(4)
nfts = cc.find_elements(locator.sample.opensea.img_okay_bear)
for nft in nfts:
src = nft.get_property("src")
name = nft.get_property("alt")
if name not in nftDic:
newDic[name]=src
finish = False

for key,value in newDic.items():
r = requests.get(value)
print("Downloading:"+ key)
imagePath = ".\image\" + key + ".jpg"
with open(imagePath,'wb') as f:
f.write(r.content)

nftDic = nftDic | newDic
if finish:
break
else:
print("next page")
cc.send_hotkey("{PGDN}")

if __name__ == "__main__":
main()
What are your feelings
Updated on 4 December 2023