Skip to main content

AI-powered smart locator with retry functionality for Robot Framework using OpenAI

Project description

Robot Framework AI Fallback Locator

An AI-powered library for Robot Framework that dynamically generates robust element locators when primary locators fail, making your tests more reliable on complex web applications.

Installation

Install the library using pip:

pip install robot-aifallbacklocator

Key Features

  • ID-First Approach: Prioritizes unique element identifiers for maximum robustness
  • AI-Powered Fallback: Uses OpenAI to intelligently locate elements when standard selectors fail
  • Modern Web App Ready: Handles complex DOM structures with nested elements effectively
  • Smart Path Handling: Automatically uses the most reliable XPath patterns for your application
  • Simple Integration: Works seamlessly with existing Robot Framework tests

Usage

Import the library in your Robot Framework test file:

*** Settings ***
Library           SeleniumLibrary
Library           AIFallbackLocator    api_key=${OPENAI_API_KEY}

Define your locators and AI fallback descriptions:

*** Variables ***
${USERNAME_FIELD}      css=#username_id
${AI_USERNAME_FIELD}   the username input field

Use the AI fallback in your tests:

*** Test Cases ***
Login Test
    Open Browser    https://example.com    chrome
    AI Fallback Locator    Input Text    USERNAME_FIELD    myusername
    # OR directly use the resolved variable
    AI Fallback Locator    Input Text    ${USERNAME_FIELD}    myusername
    Close Browser

You can also use custom keywords with fallback:

*** Keywords ***
Wait And Input Text
    [Arguments]    ${locator}    ${text}    ${timeout}=10
    [Documentation]    Input text with AI fallback if the primary locator fails
    ${status}    ${error}=    Run Keyword And Ignore Error    Input Text    ${locator}    ${text}
    Run Keyword If    '${status}' == 'FAIL'    AI Fallback Locator    Input Text    ${locator}    ${text}

How The Selectors Work

The AI Fallback Locator uses a prioritized approach to find elements:

  1. ID-First: If an element has an ID, use it directly: //*[@id='login-button']
  2. Test Attributes: Look for testing-specific attributes: //*[@data-test='username']
  3. Form Attributes: For inputs, use name/placeholder: //*[@placeholder='Enter username']
  4. Meaningful Classes: Only if needed: //*[contains(@class, 'login-button')]

This approach is much more reliable than complex hierarchical selectors and works even in deeply nested DOM structures with forms and dynamic elements.

API Key Setup

Store your OpenAI API key in a .env file or provide it when initializing the library:

*** Settings ***
Library    AIFallbackLocator    api_key=${OPENAI_API_KEY}

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

robot_aifallbacklocator-1.0.1.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

robot_aifallbacklocator-1.0.1-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file robot_aifallbacklocator-1.0.1.tar.gz.

File metadata

  • Download URL: robot_aifallbacklocator-1.0.1.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for robot_aifallbacklocator-1.0.1.tar.gz
Algorithm Hash digest
SHA256 edc38f25072c73bf8bf040a471c72f73f699580fbd9bedc4c447068a0e28a0a3
MD5 7e1857d47d4fdd7e2f7c6652bd93a921
BLAKE2b-256 260b79ebaef7d7a1c778541ac47cb4f1eba0fcd902e65bc04f6ab1ac23a8f5fc

See more details on using hashes here.

File details

Details for the file robot_aifallbacklocator-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for robot_aifallbacklocator-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 759e878fc3b42f5b67227e0aaf44d3d6f05e584b6df254b1674996464fcad620
MD5 5a31a5d47ad610affb375c9ecb785ef5
BLAKE2b-256 86a862799a6eb6ed95c31aebf74af3502e570784d410f2371e550ca98b087e2f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page