| 499 | |
| 500 | // Get element value (handles different element types) |
| 501 | getElementValue(xpath) { |
| 502 | const element = this.findElement(xpath); |
| 503 | if (!element) { |
| 504 | return { success: false, error: 'Element not found', xpath: xpath }; |
| 505 | } |
| 506 | |
| 507 | let value = ''; |
| 508 | const tagName = element.tagName.toLowerCase(); |
| 509 | |
| 510 | if (tagName === 'input' || tagName === 'textarea') { |
| 511 | value = element.value; |
| 512 | } else if (tagName === 'select') { |
| 513 | const selectedOption = element.options[element.selectedIndex]; |
| 514 | value = { |
| 515 | value: element.value, |
| 516 | text: selectedOption ? selectedOption.text : '', |
| 517 | selectedIndex: element.selectedIndex |
| 518 | }; |
| 519 | } else if (element.isContentEditable) { |
| 520 | value = element.textContent; |
| 521 | } else { |
| 522 | value = element.textContent.trim(); |
| 523 | } |
| 524 | |
| 525 | return { |
| 526 | success: true, |
| 527 | xpath: xpath, |
| 528 | value: value, |
| 529 | tagName: tagName, |
| 530 | type: element.type || null |
| 531 | }; |
| 532 | } |
| 533 | |
| 534 | // Get comprehensive element properties |
| 535 | getElementProperties(xpath) { |