chore: auto-commit (97 archivos)
- .claude/CLAUDE.md - .claude/agents/fn-recopilador/SKILL.md - .claude/rules/INDEX.md - .claude/rules/cpp_apps.md - bash/functions/infra/build_cpp_windows.sh - cpp/CMakeLists.txt - cpp/PATTERNS.md - cpp/framework/app_base.cpp - cpp/framework/app_base.h - dev/issues/README.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
---
|
||||
name: cdp_find_by_text
|
||||
kind: function
|
||||
lang: go
|
||||
domain: browser
|
||||
version: 0.1.0
|
||||
purity: impure
|
||||
signature: "func CdpFindByText(c *CDPConn, text string, opts FindByTextOpts) (string, error)"
|
||||
description: "Busca el primer elemento cuyo innerText matchea el texto dado y retorna un selector CSS unico. Prefiere elementos hoja (no contenedores). Util para pruebas robustas que no dependen de selectores CSS fragiles del DOM. Combinable con CdpClick para click-by-text."
|
||||
tags: [browser, cdp, find, locator, accessibility]
|
||||
uses_functions:
|
||||
- cdp_evaluate_go_browser
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: error_go_core
|
||||
imports: []
|
||||
example: |
|
||||
c, _ := browser.CdpConnect(9222)
|
||||
defer browser.CdpClose(c, 0)
|
||||
sel, err := browser.CdpFindByText(c, "Submit", browser.FindByTextOpts{Tag: "button"})
|
||||
if err == nil && sel != "" {
|
||||
browser.CdpClick(c, sel)
|
||||
}
|
||||
tested: true
|
||||
tests: ["TestCdpFindByText_buildsSelectorScript"]
|
||||
test_file_path: "functions/browser/cdp_find_by_text_test.go"
|
||||
file_path: "functions/browser/cdp_find_by_text.go"
|
||||
notes: |
|
||||
- Prefiere "leafmost": si un <div> contiene un <button> con el mismo texto, retorna el button (donde suele vivir el handler).
|
||||
- Caso por defecto: substring + lowercased. Configurable via opts.Exact + opts.CaseSensitive.
|
||||
- Filtro opcional por tag para acotar la busqueda (mas rapido y menos ambiguo).
|
||||
- Retorna ("", nil) si no hay match — no es error. Error solo si el eval JS falla (conexion CDP caida).
|
||||
- Selector retornado funciona con todas las funciones cdp_* que aceptan selector.
|
||||
documentation: |
|
||||
Equivale al patron `getByText` de Playwright o `findByText` de Testing Library.
|
||||
Pensado para pruebas e2e + scraping donde los selectores CSS cambian con el
|
||||
build del frontend pero el texto visible es estable.
|
||||
|
||||
Construye el selector recorriendo desde el elemento hasta `body` con
|
||||
`tag:nth-of-type(n)`, salvo que el elemento tenga `id` (caso optimo:
|
||||
retorna `#<id>` directo).
|
||||
params:
|
||||
- name: c
|
||||
desc: "Conexion CDP activa obtenida con CdpConnect."
|
||||
- name: text
|
||||
desc: "Texto visible a buscar. Comparacion contra innerText/textContent normalizado (whitespace colapsado)."
|
||||
- name: opts
|
||||
desc: "FindByTextOpts: Tag (filtro por tag, vacio = cualquiera), Exact (default false), CaseSensitive (default false)."
|
||||
output: "Selector CSS unico (string vacio si no encuentra). Error solo si CDP rompe."
|
||||
---
|
||||
Reference in New Issue
Block a user