(selector: string, indexValue: number, attribute: string)
| 328 | } |
| 329 | |
| 330 | function buildAgentNthAttributeScript(selector: string, indexValue: number, attribute: string): string { |
| 331 | const payload = { selector, index: indexValue, attribute }; |
| 332 | return buildEvalScript(` |
| 333 | const payload = ${JSON.stringify(payload)}; |
| 334 | let nodes = []; |
| 335 | try { |
| 336 | nodes = Array.from(document.querySelectorAll(payload.selector)); |
| 337 | } catch { |
| 338 | return { ok: false, error: "Invalid selector" }; |
| 339 | } |
| 340 | const element = nodes[payload.index]; |
| 341 | if (!element) return { ok: false, error: "Element not found" }; |
| 342 | const value = element.getAttribute ? element.getAttribute(payload.attribute) : null; |
| 343 | return { ok: true, value }; |
| 344 | `); |
| 345 | } |
| 346 | |
| 347 | function buildAgentNthPropertyScript(selector: string, indexValue: number, property: string): string { |
| 348 | const payload = { selector, index: indexValue, property }; |
no test coverage detected