Add support for scanning the selected value of <select> elements (#1461)

This commit is contained in:
toasted-nutbread 2021-02-28 13:26:23 -05:00 committed by GitHub
parent f2d2ba0d25
commit fce2c51709
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -36,6 +36,7 @@ class DocumentUtil {
switch (element.nodeName.toUpperCase()) {
case 'IMG':
case 'BUTTON':
case 'SELECT':
return new TextSourceElement(element);
case 'INPUT':
imposterSourceElement = element;

View File

@ -126,6 +126,13 @@ class TextSourceElement {
case 'IMG':
content = element.getAttribute('alt') || '';
break;
case 'SELECT':
{
const {selectedIndex, options} = element;
const option = (selectedIndex >= 0 && selectedIndex < options.length ? options[selectedIndex] : null);
content = (option !== null ? option.textContent : '');
}
break;
default:
content = `${element.value}`;
break;