Blog

Automating Generation of Web Locators using Generative AI

By Nitin Bhosekar Head Analytics, Artificial Intelligence, BI Practice & Executive Vice President

Posted on Sep 25, 2024

automating-generation

The Challenge of Web Locators

Selenium, used in test automation, has been the go-to tool for web application testing for years. However, its effectiveness hinges significantly on the accuracy and robustness of web locators. Manually identifying and maintaining these locators has historically been a time-consuming, error-prone, and often frustrating task for automation engineers.

The dynamic nature of web applications exacerbates the problem. Even minor UI changes can render existing locators obsolete, necessitating constant updates to test scripts. This maintenance overhead can quickly become a bottleneck in the automation process, hindering development agility and increasing testing costs.

Generative AI based solution for Web Locators

We have recently designed and implemented solution to generate Web Locators from Web page DOM file and automating the Selenium based testing. LLMs with their language reasoning and pattern learning ability and generate content offers a promising solution to the web locator challenge.

By analyzing the page's DOM structure, LLM automatically identify and extract potential locators based on element attributes like ID, name, class, or XPath, significantly reducing manual effort and improving locator reliability.

Our solution exposes FastAPI based service that allows users to pass Web Page URL and filter that specify either “All” or specific list of locators to be extracted. GenAI Solution then uses the following steps to identify and extract locators.

  1. WebPage Analysis:
    Solution process HTML structure of web page to identify potential web elements and their attributes. This involves parsing the DOM, extracting information about elements, and understanding the relationships between them.

  2. Locator Generation:
    Based on the analyzed page structure, solution generates either list of all locators for each element or only specified list of Web elements locators. These locators typically include ID, name, class name, XPath, and CSS selectors.

Sample list of Web Locators generated using our GenAI based solution as below:

sample-list
  1. Factory Class Generation:
    Once the optimal locators are determined, we provide the option to automatically generate a factory class or return the locators and let user identify for which locators corresponding Factory methods need to be generated. Factory class encapsulates the locators, providing a centralized and maintainable way to access them from test scripts.

Sample output of Factory java class generated for identified Web locators:

factory-java-class

Solution Benefits for Automating Locator Generation:

  • Increased Efficiency:
    Automation of locator generation saves significant time and effort compared to manual identification.

  • Improved Locator Reliability:
    GenAI-generated locators are more robust and less prone to breakage due to UI changes.

  • Enhanced Test Maintainability:
    By centralizing locators in a factory class, test scripts become easier to maintain and modify.

  • Accelerated Test Development:
    With reliable locators in place, test script creation is expedited, leading to faster time-to-market.

Want to stay ahead in the world of innovation? Visit our website for more insights, resources, and updates on the latest in Generative AI technology and automation.

Click the link to explore how we’re shaping the future.

About Dilbagh Dhindsa

Innovation Head AI and Data Analytics

Dilbagh is a hands-on leader in Generative AI, AI/ML engineering, Data Science and software development. With over 20 years of International experience. He has developed groundbreaking AI and Generative AI solutions for global customers that helped solve complex business problems and optimize processes.

He had developed GenAI Accelerators for generating Sections of SoW(Statement of Work) using innovative metadata-driven dynamic chunk mapping. A US patent have been filed for the solution. Other GenAI Solutions included Secure Private GPT, an Email processor for license information, Recruitment tool for matching JD with resumes and chat.