* 设置复选框状态 * * @param {string} selector - CSS 选择器 * @param {boolean} checked - 是否选中(默认 true) * @returns {ZBrowserClient} this
(selector, checked)
| 598 | * @returns {ZBrowserClient} this |
| 599 | */ |
| 600 | check(selector, checked) { |
| 601 | return this.evaluate( |
| 602 | (selector, checked) => { |
| 603 | const el = document.querySelector(selector) |
| 604 | if (!el) { |
| 605 | throw new Error('check: unable to find element by selector "' + selector + '"') |
| 606 | } |
| 607 | el.checked = checked === undefined ? true : checked === true |
| 608 | el.dispatchEvent(new window.Event('change', { bubbles: true, cancelable: true })) |
| 609 | }, |
| 610 | selector, |
| 611 | checked |
| 612 | ) |
| 613 | } |
| 614 | |
| 615 | /** |
| 616 | * 聚焦元素 |