Skip to main content

A utility to help you locate UI elements using HTML and natural language.

Project description

talk2dom — Locate Web Elements with One Sentence

📚 English | 中文

PyPI PyPI Downloads Stars License CI

talk2dom is a focused utility that solves one of the hardest problems in browser automation and UI testing:

Finding the correct UI element on a page.


Your browser does not support the video tag.

🧠 Why talk2dom

In most automated testing or LLM-driven web navigation tasks, the real challenge is not how to click or type — it's how to locate the right element.

Think about it:

  • Clicking a button is easy — if you know its selector.
  • Typing into a field is trivial — if you've already located the right input.
  • But finding the correct element among hundreds of <div>, <span>, or deeply nested Shadow DOM trees? That's the hard part.

talk2dom is built to solve exactly that.


🎯 What it does

talk2dom helps you locate elements by:

  • Extracting clean HTML from Selenium WebDriver or any WebElement
  • Formatting it for LLM consumption (e.g. GPT-4, Claude, etc.)
  • Returning minimal, clear selectors (like xpath: ... or css: ...)
  • Playing nicely with Shadow DOM traversal (you handle it your way)

🤔 Why Selenium?

While there are many modern tools for controlling browsers (like Playwright or Puppeteer), Selenium remains the most robust and cross-platform solution, especially when dealing with:

  • ✅ Safari (WebKit)
  • ✅ Firefox
  • ✅ Mobile browsers
  • ✅ Cross-browser testing grids

These tools often have limited support for anything beyond Chrome-based browsers. Selenium, by contrast, has battle-tested support across all major platforms and continues to be the industry standard in enterprise and CI/CD environments.

That’s why talk2dom is designed to integrate directly with Selenium — it works where the real-world complexity lives.


📦 Installation

pip install talk2dom

🔍 Usage Example

Basic Usage

By default, talk2dom uses gpt-4o-mini to balance performance and cost. However, during testing, gpt-4o has shown the best performance for this task.

Make sure you have OPENAI_API_KEY

export OPENAI_API_KEY="..."

Sample Code

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

from talk2dom import ActionChain

driver = webdriver.Chrome()

ActionChain(driver) \
    .open("http://www.python.org") \
    .find("Find the Search box") \
    .type("pycon") \
    .type(Keys.RETURN) \
    .assert_page_not_contains("No results found.") \
    .close()

Free Models

You can also use talk2dom with free models like llama-3.3-70b-versatile from Groq.

Make sure you have a Groq API key

export GROQ_API_KEY="..."

Sample Code with Groq

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from talk2dom import ActionChain

driver = webdriver.Chrome()
# Use LLaMA-3 model from Groq (fast and free)
ActionChain(driver, model="llama-3.3-70b-versatile", model_provider="groq") \
    .open("http://www.python.org") \
    .find("Find the Search box") \
    .type("pycon") \
    .type(Keys.RETURN) \
    .assert_page_not_contains("No results found.") \
    .close()

Full page vs Scoped element queries

The get_element() function can be used to query the entire page or a specific element. You can pass either a full Selenium driver or a specific WebElement to scope the locator to part of the page.

Why/When use WebElement instead of driver?

  1. Reduce Token Usage — Passing a smaller HTML subtree (like a modal or container) instead of the full page saves LLM tokens, reducing latency and cost.
  2. Improve Locator Accuracy — Scoping the query helps the LLM focus on relevant content, which is especially helpful for nested or isolated components like popups, drawers, and cards.

You don’t need to extract HTML manually — talk2dom will automatically use outerHTML from any WebElement you pass in.

sample code

modal = driver.find_element(By.CLASS_NAME, "modal")
elem = get_element(driver, "Find the confirm button", element=modal)

✨ Philosophy

Our goal is not to control the browser — you still control your browser. Our goal is to find the right DOM element, so you can tell the browser what to do.


✅ Key Features

  • 📍 Locator-first mindset: focus on where, not how
  • 🧠 Built for LLM-agent workflows
  • 🧩 Shadow DOM friendly (you handle traversal, we return selectors)

📄 License

Apache 2.0


Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.


💬 Questions or ideas?

We’d love to hear how you're using talk2dom in your AI agents or testing flows.
Feel free to open issues or discussions!

⭐️ If you find this project useful, please consider giving it a star!

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

talk2dom-0.1.7.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

talk2dom-0.1.7-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file talk2dom-0.1.7.tar.gz.

File metadata

  • Download URL: talk2dom-0.1.7.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.8

File hashes

Hashes for talk2dom-0.1.7.tar.gz
Algorithm Hash digest
SHA256 07f08ea3e20deb4e08669fa1fed0855d2f027e1fab14e56a523e048873d1a8be
MD5 4df34c3ae9dc97f1927c4456d505744b
BLAKE2b-256 22ad663e4ffcaa31ca7b812ec1593599b5bfdf6fbe60123269f079a32b01366f

See more details on using hashes here.

File details

Details for the file talk2dom-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: talk2dom-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.8

File hashes

Hashes for talk2dom-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 44aa901c86a5f62bef15467f9436219984cd98c07efb0d3e8e7e80f07cb75df0
MD5 702f51f818990303bbc8112cb93ccff2
BLAKE2b-256 29f4dfb324388b2b52bf150cd872e62853962d741b621889eeb5d97371a013e5

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