MCPcopy
hub / github.com/ZToolsCenter/ZTools / value

Method value

resources/zbrowser/client.js:571–591  ·  view source on GitHub ↗

* 设置表单元素的值 * * 设置后会触发 input(文本框)或 change(其它类型)事件。 * * @param {string} selector - CSS 选择器 * @param {string} value - 要设置的值 * @returns {ZBrowserClient} this

(selector, value)

Source from the content-addressed store, hash-verified

569 * @returns {ZBrowserClient} this
570 */
571 value(selector, value) {
572 return this.evaluate(
573 (selector, value) => {
574 const el = document.querySelector(selector)
575 if (!el) {
576 throw new Error('value: unable to find element by selector "' + selector + '"')
577 }
578 el.value = value
579 if (
580 el.tagName === 'TEXTAREA' ||
581 (el.tagName === 'INPUT' && ['text', 'password', 'search'].includes(el.type))
582 ) {
583 el.dispatchEvent(new window.Event('input', { bubbles: true, cancelable: true }))
584 } else {
585 el.dispatchEvent(new window.Event('change', { bubbles: true, cancelable: true }))
586 }
587 },
588 selector,
589 value
590 )
591 }
592
593 /**
594 * 设置复选框状态

Callers 1

weightedSearchFunction · 0.80

Calls 1

evaluateMethod · 0.95

Tested by

no test coverage detected