Skip to main content

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

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

Robot Framework DomRetryLibrary

A Robot Framework library with AI-powered fallback for locator variables, enhancing test reliability by using OpenAI to dynamically generate element locators when primary locators fail.

What's New in Version 4.0.0

  • Major improvement in reliability with a complete redesign of XPath generation strategy
  • New ID-First approach that prioritizes direct element selection using unique attributes
  • Simplified selectors that don't break with complex DOM structures or forms
  • Optimized for modern web applications with dynamic and nested elements

Installation

Install the library using pip:

pip install robotframework-domretrylibrary

Usage

Import the library in your Robot Framework test file:

*** Settings ***
Library           SeleniumLibrary
Library           DomRetryLibrary

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 (either with variable name or resolved variable):

*** Test Cases ***
Login Test
    Open Browser    https://example.com    chrome
    # Both syntaxes work in version 3.1.0+
    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 New Selectors Work (v4.0.0+)

The library now 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    DomRetryLibrary    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

robotframework_domretrylibrary-4.0.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

robotframework_domretrylibrary-4.0.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file robotframework_domretrylibrary-4.0.0.tar.gz.

File metadata

File hashes

Hashes for robotframework_domretrylibrary-4.0.0.tar.gz
Algorithm Hash digest
SHA256 26c5dc3eea04fbae3f2a1d6996b9bba618e1e2375c3ba237f9f71508a6d9c07e
MD5 1af8b2177b71cfb9e2b7e0e3900d8643
BLAKE2b-256 065086aa290e22acc427ce9e9daa65659e8a2ea2fe246c071962d9f6f29104a0

See more details on using hashes here.

File details

Details for the file robotframework_domretrylibrary-4.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for robotframework_domretrylibrary-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7fdc2b0c4dce7c2827fba3b90e1a0dbced7518bbb241db16b6f3684c4c926b6
MD5 6686b159509bb822ec4d3a31bdffce39
BLAKE2b-256 29d05ad943f47346a59c39e68ff35a0ed8dddba6ce14a79f5e176c6464329424

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