* React-compatible form filling. * Sets value via native setter and dispatches input + change events. * @param {HTMLInputElement} el * @param {string} value
(el, value)
| 216 | * @param {string} value |
| 217 | */ |
| 218 | function fillInput(el, value) { |
| 219 | throwIfStopped(); |
| 220 | const nativeInputValueSetter = Object.getOwnPropertyDescriptor( |
| 221 | window.HTMLInputElement.prototype, |
| 222 | 'value' |
| 223 | ).set; |
| 224 | nativeInputValueSetter.call(el, value); |
| 225 | el.dispatchEvent(new Event('input', { bubbles: true })); |
| 226 | el.dispatchEvent(new Event('change', { bubbles: true })); |
| 227 | console.log(LOG_PREFIX, `已填写输入框 ${el.name || el.id || el.type}: ${value}`); |
| 228 | log(`已填写输入框 [${el.name || el.id || el.type || '未知'}]`); |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Fill a select element by setting its value and triggering change. |
no test coverage detected