2026-11-26 15:40 UTC

Selenia releases a 24 MB local natural-language locator for Selenium

state: seedheat: lowuncertainty: mediumrelevance: mediumsmall-models browser-automation software-testingPenielny

What is this?

Selenia is an MIT-licensed Python tool by GitHub user Penielny, presented in its repository as a natural-language locator for existing Selenium tests. The project says its roughly 24 MB, int8 ONNX model ranks real page elements against a text description and returns a Selenium WebElement; it is installable with pip. The repository reports 89.4% top-1 accuracy on 161 held-out queries from sites not used in training, and about 20–35 ms per lookup on an Apple M1. These are developer-reported figures, not independently verified. Search snippets for the same repository and its releases describe an LLM/Ollama-based version, conflicting with the supplied current repository text; the available sources do not establish the history or timing of that discrepancy.

Why it matters

This is a focused alternative to brittle hand-written locators and slower hosted browser agents, not an autonomous browser agent or a general-purpose small language model. If the reported performance holds in real test suites, it could make natural-language element selection practical in existing Selenium workflows while keeping page data local and avoiding per-call API costs. The small evaluation set and conflicting indexed descriptions warrant caution about general reliability and project evolution.

Current assessment

The supplied GitHub README describes Selenia as available now via pip: a local cross-encoder, fine-tuned from ms-marco-MiniLM-L-6-v2 on about 28,800 description/element pairs, exported to int8 ONNX. On first use it downloads about 24 MB; thereafter the developer says it runs offline. It ranks elements already present on the page rather than generating selectors, returns standard Selenium elements, and can refuse low-confidence or ambiguous matches. The project reports 89.4% top-1 and 96.3% top-3 on 161 held-out queries from unseen sites, versus 82.6% and 93.8% for the base model; it also reports 20–35 ms per lookup on an M1 after a one-time 0.4-second model load. These are first-party claims and the supplied evidence contains no independent benchmark or adoption evidence. Scope limits include no autonomous multi-step planning and no iframe search unless the test switches into the frame. Google results include snippets for the same repository describing LLM/Ollama support, at odds with the supplied README and current search snippets describing a small local ranker; the reason and version chronology are unconfirmed, so track the repository/version before treating either description as the full history. The practical implication, if validated, is a privacy-preserving, low-latency way to reduce locator maintenance in Selenium testsβ€”not proof that browser testing as a whole becomes robust.

Measured heat

now 1 pts/hpeak 6 pts/hcomments 0/hpeers p89momentum: steady2 platformsage 3h
points/hour across evidence Β· reading as of 2026-11-27 02:23:58.509736+11:00 Β· deterministic, not a model opinion

How the heat travelled

11-26 13:00⭐ origin echo-reconstructedThe repository itself is the original artifact; the HN Show post links directly to it, and the README contains the project description: β€œA s
Penielny (@penielny) on github (echo) Β· attributed from hn.story.50654686
β€”
11-26 12:42first on hacker news Β· published Β· +-0.3hShow HN: Selenia – Plain-English Selenium locators from a 24 MB model, no LLM
penielny
β€”
11-26 12:42amplified on hacker news πŸ‘‘hn.story.50654686
penielny
peak 4 Β· 0 comments Β· 99% of case engagement
11-26 13:20our radar first saw it Β· +0.3hdiscovery anchor: hn.story.50654686β€”
pace: p67 vs 1311 stories at the 2h mark (now 3h old) β€” ahead of agentfx-agent-animation-tool (1.3x), behind adversarial-verification-layer-production-agent-stacks (0.8x)

Evidence (2) β€” ⭐ canonical anchor

sourceobjectauthorscorecomments
🟧 hnShow HN: Selenia – Plain-English Selenium locators from a 24 MB model, no LLM
Retrieved article excerpt

Open article Β· Retrieved 2026-11-26T13:21:39.538729+00:00

# Selenia

[PyPI](https://pypi.org/project/selenia/)
[Python](https://pypi.org/project/selenia/)
[Tests](https://github.com/penielny/selenia/actions/workflows/tests.yml)
[Downloads](https://pepy.tech/project/selenia)
[License: MIT](https://github.com/penielny/selenia/blob/main/LICENSE)

**Stop maintaining brittle XPath. Find Selenium elements with plain English, using a 24 MB model
that runs locally. No LLM, no API key, no per-call cost.**

[A pytest login test using selenia.find('username field'), find('password field') and find('the login button') running against saucedemo.com and passing](https://github.com/penielny/selenia/blob/main/docs/demo.gif)

A real run: every element is chosen by the model from the page's own elements.

|  |  |
| --- | --- |
| 🎯 **89% top-1 / 96% top-3** | on websites the model never saw during training |
| ⚑ **~20–35 ms per `find`** | on a laptop CPU (Apple M1), after a one-time 0.4 s model load |
| πŸ”’ **100% local** | nothing leaves your machine; works offline and in locked-down CI |
| πŸ›‘ **Never guesses** | raises when nothing fits, or when two elements fit equally well |



---

## Why Selenia?

Locators break whenever the front end changes: a renamed class, a moved `div`, a regenerated id.
LLM browser agents can avoid that, but they need an API key, send your pages to a third party, cost
money on every step, take seconds per action, and can confidently pick the wrong element.

Selenia does one job: it turns a description into an element. A small fine-tuned ranking model
scores the **real elements on the page** against your description and returns the best one. It
never writes a selector, so it cannot invent one.

|  | Selenia | LLM agents (browser-use, Stagehand, Skyvern…) | Hand-written XPath / CSS |
| --- | --- | --- | --- |
| Survives UI refactors | βœ… | βœ… | ❌ |
| Runs offline, no API key | βœ… | ❌ (unless you host an LLM) | βœ… |
| Cost per step | $0 | API tokens | $0 |
| Latency per element | tens of ms | seconds | ms |
| Same page + same description β†’ same element | βœ… | ❌ | βœ… |
| Refuses ambiguous matches | βœ… | ❌ | n/a |
| Plans multi-step tasks on its own | ❌ | βœ… | ❌ |

If you want an autonomous agent, use an agent. If you want reliable, fast, free locators inside the
Selenium tests you already have, use Selenia.

## πŸ“¦ Installation

```
pip install selenia
```

Or from source:

```
pip install .
```

## πŸ› οΈ Usage

```
from selenium import webdriver
from selenia import Selenia

driver = webdriver.Chrome()
selenia = Selenia(driver)   # downloads the model on first use

driver.get("https://www.saucedemo.com/")
selenia.find("username field").send_keys("standard_user")
selenia.find("password field").send_keys("secret_sauce")
selenia.find("the login button").click()

# Find all matching elements, best match first
buttons = selenia.find_all("add to cart button")
```

`find` returns a normal Selenium `WebElement`, so it works alongside your existing code, waits and
page objects. Elements inside open shadow DOM are found too.

More runnable scripts, including a full checkout flow, error handling and a pytest suite, are in
[examples/](https://github.com/penielny/selenia/blob/main/examples/README.md).

## 🎯 How matches are chosen

- `find` raises Selenium's `NoSuchElementException` when the model is not confident (`min_score`,
  default 0.5) or when two elements fit equally well (`min_margin`, default 0.05). The message
  names the candidates, so you can see what to add to the description.
- `find_all` returns every element scoring at least `min_score`, best first.
- Tune both with `LocalRanker(min_score=..., min_margin=...)`; `min_margin=0` always takes the top pick.
- iframes are not searched: switch into the frame first, then call `find`.

## 🧩 The model

A cross-encoder (based on `ms-marco-MiniLM-L-6-v2`) fine-tuned on about 28,800 description/element
pairs collected from real websites, then exported to int8 ONNX. It runs on `onnxruntime` and
`tokenizers`, so there is no PyTorch dependency.

| Held-out evaluation (161 queries, sites unseen in training) | top-1 | top-3 | MRR |
| --- | --- | --- | --- |
| Base model, before fine-tuning | 82.6% | 93.8% | 0.890 |
| **Selenia, shipped int8 ONNX model** | **89.4%** | **96.3%** | **0.933** |

The first time you create a `Selenia`, it downloads the model (about 24 MB) into `~/.cache/selenia`
and verifies its checksum. After that it runs offline.

- `SELENIA_CACHE_DIR` changes where the download is kept.
- `SELENIA_MODEL_URL` fetches from your own mirror instead of the GitHub release.
- To use a model you trained yourself, pass `LocalRanker(model_dir="training/models/selenia-ce")`
  or set `SELENIA_MODEL_DIR`. That is the folder written by `training/train.py`.

### Train it on your own app

The full pipeline that produced the model (collecting pages, labelling, generating descriptions,
fine-tuning, int8 export and evaluation) is in [training/](https://github.com/penielny/selenia/blob/main/training/README.md). Retraining on
screens from your own product is the fastest way to push accuracy higher for your tests.

## πŸ§ͺ Running Tests

```
python -m pytest tests/
```

The tests in `tests/test_browser.py` drive a headless Chrome against a local page and are skipped
when Chrome cannot start. The ones that use the real model are also skipped unless a trained model
is at `training/models/selenia-ce` or `SELENIA_MODEL_DIR`.

## 🀝 Contributing

Issues and pull requests are welcome. Especially useful: pages where Selenia picks the wrong
element (open an issue with the URL and your description), so they can be added to the training
and evaluation data.

If Selenia saves you from fixing a broken locator, a ⭐ helps other people find it.

## πŸ“„ License

[MIT](https://github.com/penielny/selenia/blob/main/LICENSE)

---

Made with ❀️ by Penielny
penielny40
🟧 echo.github ⭐The repository itself is the original artifact; the HN Show post links directly to it, and the README contains the project description: β€œA sPenielny (@penielny)β€”β€”

Interpretation history

Decision trace