1. Introduction #
Clicknium’s Locator supports a parametric locator, which can be utilized by users in their automation projects to replace variables or data. By doing so, the locator can match a series of elements rather than just a single one.
To illustrate how to use an index variable in the locator to identify a series of elements, there are two automation cases available.
Note: For more about the installation and the tutorial of Clicknium Automation, please refer to here.
2. Automation Case-1 #
Case Description : Scraping contact list on the slack client,Scraping contact list on the Slack client to obtain user information.
![](http://clicknium.com/wp-content/uploads/2023/11/slack_contact_list.png)
After recording one contact item’s locator, the user modifies the locator with an index variable.
![](http://clicknium.com/wp-content/uploads/2023/11/slack_locator-1024x346.png)
Then use loop traversal to locate each contact element and get information.
for i in range(1,13):
dict = {"index":i}
if not cc.is_existing(locator.slack.listitem_member, dict):
continue
elem_member = ui(locator.slack.listitem_member, dict)
name = elem_member.get_text()
3. Automation Case-2 #
Case description:Scraping playlist from Spotify. It is an actual user scenario, which needs to get the playlist information from spotify.
First, locate “author” and “title” from one item in the playlist.
![](http://clicknium.com/wp-content/uploads/2023/11/spotify_playlist-1024x741.png)
As the Spotify page is complicated and dynamic, users use “XPath” in the locator.
Modify the locator with the index variable.
![](http://clicknium.com/wp-content/uploads/2023/11/spofity_author_locator-1024x151.png)
![](http://clicknium.com/wp-content/uploads/2023/11/spofity_title_locator-1024x151.png)
Then use loop traversal to locate each item in the playlist and get information.
tab = cc.chrome.open("https://open.spotify.com/playlist/6iwz7yurUKaILuykiyeztu")
index = 2
titles = []
artists = []
links = []
while True:
if not tab.is_existing(locator.chrome.open.div_title, {'index':index}):
break
title = tab.find_element(locator.chrome.open.div_title, {'index':index}).get_text()
artist = []
link = []
element = tab.find_element(locator.chrome.open.div_author, {'index':index})
authers = element.children
for item in element.children:
artist.append(item.get_text())
link.append(item.get_property('href'))
titles.append(title)
artists.append(artist)
links.append(link)
index += 1
tab.close()