(selector: string, indexValue: number)
| 311 | } |
| 312 | |
| 313 | function buildAgentNthValueScript(selector: string, indexValue: number): string { |
| 314 | const payload = { selector, index: indexValue }; |
| 315 | return buildEvalScript(` |
| 316 | const payload = ${JSON.stringify(payload)}; |
| 317 | let nodes = []; |
| 318 | try { |
| 319 | nodes = Array.from(document.querySelectorAll(payload.selector)); |
| 320 | } catch { |
| 321 | return { ok: false, error: "Invalid selector" }; |
| 322 | } |
| 323 | const element = nodes[payload.index]; |
| 324 | if (!element) return { ok: false, error: "Element not found" }; |
| 325 | const value = element.value !== undefined ? element.value : ""; |
| 326 | return { ok: true, value: typeof value === "string" ? value : String(value ?? "") }; |
| 327 | `); |
| 328 | } |
| 329 | |
| 330 | function buildAgentNthAttributeScript(selector: string, indexValue: number, attribute: string): string { |
| 331 | const payload = { selector, index: indexValue, attribute }; |
no test coverage detected