Element-Selector-tree-tool (Source) (View on Greasyfork)
A powerful userscript that provides developer-friendly CSS selectors for any DOM element with visual highlighting and a hierarchical tree view.
Why it’s useful: Click any element to copy a precise, unique selector so AI or automation can generate a working userscript faster with fewer mistakes.
![]() |
![]() |
- One-Click Copy and quick view: Click any highlighted element to copy its selector to clipboard
- Interactive Tree View: Shows element hierarchy with syntax highlighting
- Smart Selector Generation: Prioritizes reliable selectors (ID → data attributes → unique classes → semantic attributes)
- Menu Options: Change hotkeys and toggle enable/disable directly from the menu
- Install a userscript manager like Tampermonkey or Violentmonkey or Userscript
- Click here to install the script
- The script will automatically run on all websites
- Setup your own hotkey!:

- hotkey defaults to
Ctrl+E, you can change this in the menu *
- Activate: Press
Ctrl+Eon any webpage - Inspect: Hover over elements to see their selectors and hierarchy
- Copy: Click on any highlighted element to copy its CSS selector
- Deactivate: Press
Ctrl+Eagain to exit selector mode
The tool generates selectors in this priority order:
- ID:
#unique-id(most reliable) - Data Attributes:
[data-testid],[data-cy],[data-test] - Stable Class Combo:
button.primary.large(avoids hashed/dynamic classes) - ARIA Attributes:
[role="button"],[aria-label="Close"] - Semantic Elements:
input[name="email"],button[type="submit"] - Contextual :has() (when applicable): e.g.
label[for="id"]:has(+ input) - Hierarchical Path: nearest‑ID path using
:nth-of-typewhen needed
Feel free to submit issues or pull requests to improve the tool's selector generation or user experience.
This project is licensed under the Apache License, Version 2.0 with Commons Clause License Condition v1.0 - see the LICENSE file for details.

