Using Crawl Custom Action

Modified on Tue, 23 Apr 2024 at 02:35 PM

Crawl Custom Action Overview


The main purpose of the crawl method is to reduce the number of test cases for different categories (main and sub) by replacing unique XPaths with a common XPath. This reduces the effort required for writing unique XPaths for all the categories.


The following code snippet is written in Java and is used for automating the process of clicking through a hierarchical menu structure on a web page.


Code Snippet

Use Case 


The following use case explains how to automate the navigation through main and sub-categories on the Amazon website using Selenium WebDriver with Java.  The summary provides code snippet with a short description  on navigating through categories, handling web element accessibility, and updating the code for additional categories on the Amazon website.


Prerequisites

  • Basic knowledge of Java programming
  • Selenium WebDriver installed

Custom Action Summary

Field Description
Navigate through categoriesFind all main category elements using List<WebElement> mainCategory = driver.findElements(By.xpath("//ul[@id='nav-main-menu']/li"));.
Loop through each main category element and click on it using mainCategory.get(i).click();.
Find all sub-category elements using List<WebElement> subCategory = driver.findElements(By.xpath("//div[@id='nav-sub-menu']/div"));.
Common Xpath are provided. Crawler action uses these Xpath by indexing approach it will go through all the categories.
Looping subcategory

Loop through each subcategory element and click on it using subCategory.get(k).click();.

Perform category-specific actionsPerform any actions specific to each category, such as crawling each and every product or corresponding category is displayed PLP 
Return to main pageUse driver.navigate().back(); to return to the main page after processing each sub-category. The loop will continue until all the categories and subcategories are processed.



Tip - To create, add and update custom action, refer to the article How to use custom methods.



Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article