npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

locatai-js

v0.1.0

Published

Enterprise-grade AI-powered element locator for Selenium WebDriver

Readme

LocatAI-js

License Version Downloads

LocatAI is an enterprise-grade AI-powered element locator for Selenium WebDriver. It makes your test automation more reliable by using AI to dynamically locate web elements based on natural language descriptions.

Features

  • AI-Powered Element Location: Find elements using natural language descriptions
  • Multiple AI Provider Support: Works with OpenAI, Anthropic/Claude, Google Gemini, and Ollama
  • Smart Caching: Caches successful locators to improve performance and reduce API costs
  • Adaptive Retry Logic: Tries multiple locator strategies with intelligent fallbacks
  • WebDriver Extension: Seamlessly extends the Selenium WebDriver with findElementByLocatAI method
  • JSON Configuration: Simple setup with appsettings.json
  • Cross-Browser Compatibility: Works with all browsers supported by Selenium WebDriver

Installation

npm install locatai-js

Quick Start

Using JSON Configuration (Recommended)

Create an appsettings.json file with your configuration:

{
  "AI": {
    "Provider": "openai",
    "ApiKey": "your-api-key-here",
    "Model": "gpt-4o-mini"
  },
  "Options": {
    "MinimumConfidence": 0.6,
    "MaxLocatorsToTry": 3,
    "TimeoutMilliseconds": 10000,
    "EnableDetailedLogging": false,
    "EnableLocatorRetry": true,
    "MaxRetryAttempts": 2,
    "CacheDirectory": "./LocatAICache"
  }
}

Then in your test file:

const { Builder } = require('selenium-webdriver');
const LocatAI = require('locatai-js');
const path = require('path');

async function runTest() {
  // Create a WebDriver instance
  const driver = await new Builder().forBrowser('chrome').build();
  
  // Initialize LocatAI with your configuration
  LocatAI.initialize(driver, path.join(__dirname, 'appsettings.json'));
  
  try {
    // Navigate to a website
    await driver.get('https://www.saucedemo.com');
    
    // Find elements using natural language descriptions
    const username = await driver.findElementByLocatAI('username input field');
    const password = await driver.findElementByLocatAI('password input field');
    const loginButton = await driver.findElementByLocatAI('login button');
    
    // Interact with elements normally
    await username.sendKeys('standard_user');
    await password.sendKeys('secret_sauce');
    await loginButton.click();
    
    // Find multiple elements
    const inventoryItems = await driver.findElementsByLocatAI('inventory item');
    console.log(`Found ${inventoryItems.length} items`);
  } finally {
    await driver.quit();
  }
}

runTest();

Using Environment Variables

You can also initialize with environment variables:

// Set environment variables
process.env.OPENAI_API_KEY = 'your-openai-api-key';

const { Builder } = require('selenium-webdriver');
const LocatAI = require('locatai-js');

async function runTest() {
  const driver = await new Builder().forBrowser('chrome').build();
  
  // Initialize with a configuration object
  LocatAI.initialize(driver, {
    AI: {
      Provider: 'openai',
      ApiKey: process.env.OPENAI_API_KEY
    },
    Options: {
      EnableDetailedLogging: true
    }
  });
  
  // Now use driver.findElementByLocatAI() as needed
}

AI Provider Configuration

LocatAI-js supports the following AI providers:

| Provider | Configuration Key | Environment Variable | |-----------|-------------------|----------------------| | OpenAI | openai | OPENAI_API_KEY | | Anthropic | anthropic | ANTHROPIC_API_KEY | | Google | gemini | GEMINI_API_KEY | | Ollama | ollama | OLLAMA_HOST |

Advanced Configuration

You can customize the behavior with additional options:

const options = {
  AI: {
    Provider: 'openai',
    ApiKey: 'your-api-key',
    Model: 'gpt-4o' // Specify a specific model
  },
  Options: {
    // Element finder settings
    MinimumConfidence: 0.7,       // Minimum confidence score to accept a locator
    MaxLocatorsToTry: 5,          // Maximum number of locators to try
    
    // Timing settings
    TimeoutMilliseconds: 15000,   // Timeout for finding elements
    
    // Retry settings
    EnableLocatorRetry: true,     // Whether to retry failed locators
    MaxRetryAttempts: 3,          // How many times to retry
    
    // Caching settings
    CacheDirectory: './LocatAICache', // Where to store the cache
    
    // Debug settings
    EnableDetailedLogging: true   // Log detailed information about locators
  }
};

LocatAI.initialize(driver, options);

API Reference

Main Methods

LocatAI.initialize(driver, config)

Initializes LocatAI and extends the WebDriver instance with additional methods.

| Parameter | Type | Description | |-----------|------|-------------| | driver | WebDriver | The Selenium WebDriver instance | | config | Object|String | Configuration object or path to appsettings.json |

driver.findElementByLocatAI(description)

Finds a single element using natural language.

| Parameter | Type | Description | |-----------|------|-------------| | description | String | Natural language description of the element | | Returns | WebElement | The found element |

driver.findElementsByLocatAI(description)

Finds multiple elements using natural language.

| Parameter | Type | Description | |-----------|------|-------------| | description | String | Natural language description of the elements | | Returns | Array | Array of found elements |

Enterprise Support

For enterprise support, custom integration, or training, please contact us at [email protected].

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.