In a nutshell
Note: If the page loads content asynchronously, pair Get Count task with a <Wait> task to ensure the element is rendered before the count is captured.<variable> = getCount(<locator>);
| Parameter | Data Type | Description |
| variable | LONG | Stores the number of matching elements found. |
| locator | STRING | Identifies the element whose count is to be fetched. Note: Locators can be fetched in one of two ways, either by manually inspecting the webpage to identify the element, or by using a recorded element saved during a recording session. Learn more about Elements. |
// Open the ZWatch Commerce home page using the Open URL task
openURL("https://zwatch.zohocommerce.com/", "same window");
// Wait until the product cards are present on the page
wait(10, ".theme-prod-box", event.PRESENT);
// Create a variable 'productCount' to store the number of product cards found
productCount = getCount(".theme-prod-box");
// output: 8
// Confirm the count matches the expected number of featured products using conditional logic
if (productCount != 8)
{
throwError("Home page does not show the expected number of product cards"); //Learn more about Throw Error task
}where:
| "https://zwatch.zohocommerce.com/" | ZWatch Commerce home page URL. |
| "same window" | Opens the page in the window already running the test. |
| 10 | Maximum time to wait for the product cards to be present, in seconds. |
| .theme-prod-box | Locator matching each product card. |
| event.PRESENT | Waits until the product cards exist on the page. |
| productCount | Variable storing the number of product cards found. |
| 8 | Expected number of product cards on the home page. |
Enters a search term into the ZWatch Commerce search box and submits it. The script then counts the returned result rows to confirm the search isn't empty.
// Open the ZWatch Commerce home page using the Open URL task
openURL("https://zwatch.zohocommerce.com/", "same window");
// Click the search icon to reveal the search input using the Click task
click(".theme-search");
// Enter a search term into the search box using the Set Value task
setValue("[data-search-input]", "Chrono 44");
// Submit the search by pressing Enter using the Send Keys task
sendKeys("[data-search-input]", [keys.ENTER]);
// Wait until the search result rows are present
wait(10, ui.zwatch.search-result-row, event.PRESENT);
// Create a variable 'resultCount' to store the number of search results found
resultCount = getCount(ui.zwatch.search-result-row);
// Confirm at least one result was found using conditional logic
if (resultCount == 0)
{
throwError("No search results were found"); //Learn more about Throw Error task
}where:
| "https://zwatch.zohocommerce.com/" | ZWatch Commerce home page URL. |
| "same window" | Opens the page in the window already running the test. |
| .theme-search | Locator for the search icon. |
| [data-search-input] | Locator for the search box. |
| "Chrono 44" | Search term entered into the search box. |
| keys.ENTER | Simulated key press used to submit the search. |
| 10 | Maximum time to wait for the search result rows to be present, in seconds. |
| ui.zwatch.search-result-row | Locator matching each search result row. |
| resultCount | Variable storing the number of results found. |
Verifies that the ZWatch Commerce site header shows the expected number of navigation links.
// Open the ZWatch Commerce home page using the Open URL task
openURL("https://zwatch.zohocommerce.com/", "same window");
// Wait until the navigation links are present on the page
wait(10, ".theme-menu a", event.PRESENT);
// Create a variable 'navLinkCount' to store the number of navigation links found
navLinkCount = getCount(".theme-menu a");
// output: 3
// Confirm the count matches the expected number of navigation links using conditional logic
if (navLinkCount != 3)
{
throwError("Site header does not show the expected number of navigation links"); //Learn more about Throw Error task
}where:
| "https://zwatch.zohocommerce.com/" | ZWatch Commerce home page URL. |
| "same window" | Opens the page in the window already running the test. |
| 10 | Maximum time to wait for the navigation links to be present, in seconds. |
| .theme-menu a | Locator matching each navigation link. |
| event.PRESENT | Waits until the navigation links exist on the page. |
| navLinkCount | Variable storing the number of navigation links found. |
| 3 | Expected number of navigation links in the site header. |
Opens the Inventory report in a Zoho Creator Inventory Manager application, applies a Flagged for Reorder filter, and confirms the number of filtered records matches the expected count.
// Open the Inventory report in a Zoho Creator Inventory Manager application using the Open URL task
openURL("https://creatorapp.zoho.com/<orgname>/inventory-manager#Report:Inventory", "same window");
// Wait until the report is present on the page
wait(10, ui.inventorymanager.inventory-report, event.PRESENT);
// Click the filter icon to open the filter panel using the Click task
click(ui.inventorymanager.filter-icon);
// Click the Flagged for Reorder option under the filter using the Click task
click(ui.inventorymanager.filter-flagged-for-reorder);
// Wait until the filtered record rows are present
wait(10, ui.inventorymanager.record-row, event.PRESENT);
// Create a variable 'flaggedCount' to store the number of filtered records found
flaggedCount = getCount(ui.inventorymanager.record-row);
// output: 2
// Confirm the count matches the expected number of flagged records using conditional logic tasks
if (flaggedCount != 2)
{
throwError("Unexpected number of records flagged for reorder"); //Learn more about Throw Error task
}where:
| "https://creatorapp.zoho.com/<orgname>/inventory-manager#Report:Inventory" | Inventory report URL. |
| "same window" | Opens the report in the window already running the test. |
| ui.inventorymanager.inventory-report | Locator for the Inventory report. |
| ui.inventorymanager.filter-icon | Locator for the filter icon. |
| ui.inventorymanager.filter-flagged-for-reorder | Locator for the Flagged for Reorder filter option. |
| 10 | Maximum time to wait for the report and filtered rows to be present, in seconds. |
| ui.inventorymanager.record-row | Locator matching each filtered record row. |
| flaggedCount | Variable storing the number of flagged records found. |
| 2 | Expected number of records flagged for reorder. |
Implementation
// Step 1: Open the Sol Analog product page on the ZWatch Commerce website in the same window using the Open URL task
openURL("https://zwatch.zohocommerce.com/products/sol-analog/3531661000000075636", "same window");
// Step 2: Wait until the product page has loaded
wait(10, "[data-zs-selling-price]", event.PRESENT);
// Step 3: Create a variable 'addToCartCount' to store the number of Add to Cart buttons found
addToCartCount = getCount(".theme-product-qty-and-add-cart");
// output: 0
// Step 4: Confirm the count is zero using conditional logic tasks
if (addToCartCount != 0)
{
throwError("Add to Cart option is present for an out-of-stock product"); //Learn more about Throw Error task
}Implementation
// Step 1: Open the ZWatch Commerce home page in the same window using the Open URL task
openURL("https://zwatch.zohocommerce.com/", "same window");
// Step 2: Click the search icon to reveal the search input using the Click task
click(".theme-search");
// Step 3: Enter a search term into the search box using the Set Value task
setValue("[data-search-input]", "Diver Chronomat");
// Step 4: Submit the search by pressing Enter using the Send Keys task
sendKeys("[data-search-input]", [keys.ENTER]);
// Step 5: Wait until the search result rows are present
wait(10, ui.zwatch.search-result-row, event.PRESENT);
// Step 6: Create a variable 'resultCount' to store the number of search results found
resultCount = getCount(ui.zwatch.search-result-row);
// output: 1
// Step 7: Confirm exactly one result is shown using conditional logic tasks
if (resultCount != 1)
{
throwError("Search did not return exactly one matching result"); //Learn more about Throw Error task
}Implementation
// Step 1: Open the Employee Directory page in the HR Portal application using the Open URL task
openURL("https://creatorapp.zoho.com/<orgname>/hr-portal#Page:Employee_Directory", "same window");
// Step 2: Wait until the search field is present on the page
wait(10, ui.hrportal.search-field, event.PRESENT);
// Step 3: Enter the department name into the search field using the Set Value task
setValue(ui.hrportal.search-field, "Engineering");
// Step 4: Click the Search button to filter the embedded report using the Click task
click(ui.hrportal.search-button);
// Step 5: Wait for the filtered results to load in the embedded report
wait(10, ui.hrportal.employees-report-frame, event.PRESENT);
// Step 6: Switch into the embedded report iframe using the Switch To task
switchTo(ui.hrportal.employees-report-frame, True);
// Step 7: Wait until the employee record rows are present within the iframe
wait(10, ui.hrportal.employee-record-row, event.PRESENT);
// Step 8: Create a variable 'employeeCount' to store the number of matching employee records found
employeeCount = getCount(ui.hrportal.employee-record-row);
// output: 4
// Step 9: Confirm the count matches the expected number of employees in the Engineering department using conditional logic tasks
if (employeeCount != 4)
{
throwError("Employee count does not match the expected number for the selected department"); //Learn more about Throw Error task
}Now that you've learned how to count matching elements using the Get Count task, learn how to retrieve an element's width using the Get Element Width task.
Before using the Get Count task, ensure that you've learned how to retrieve an element's attribute value using the Get Attribute task