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

Method hover

resources/zbrowser/client.js:368–403  ·  view source on GitHub ↗

* 鼠标悬停 * * 支持两种调用方式: * 1. hover(selector) - 在元素上悬停 * 2. hover(x, y) - 在坐标位置悬停(物理鼠标移动) * * @returns {ZBrowserClient} this

(...args)

Source from the content-addressed store, hash-verified

366 * @returns {ZBrowserClient} this
367 */
368 hover(...args) {
369 if (typeof args[0] === 'number' && typeof args[1] === 'number') {
370 // hover(x, y) - 坐标物理鼠标移动
371 this._queue.push({ method: 'mouseEvent', args: ['mouseMove', args[0], args[1]] })
372 return this
373 }
374 if (typeof args[0] === 'string') {
375 // hover(selector) - 触发 mouseover/mouseenter 事件
376 return this.evaluate((selector) => {
377 const element = document.querySelector(selector)
378 if (!element) {
379 throw new Error('hover: unable to find element by selector "' + selector + '"')
380 }
381 const rect = element.getBoundingClientRect()
382 element.dispatchEvent(
383 new window.MouseEvent('mouseenter', {
384 view: window,
385 bubbles: false,
386 cancelable: false,
387 clientX: rect.left + rect.width / 2,
388 clientY: rect.top + rect.height / 2
389 })
390 )
391 element.dispatchEvent(
392 new window.MouseEvent('mouseover', {
393 view: window,
394 bubbles: true,
395 cancelable: true,
396 clientX: rect.left + rect.width / 2,
397 clientY: rect.top + rect.height / 2
398 })
399 )
400 }, args[0])
401 }
402 throw new Error('hover: parameter error')
403 }
404
405 /**
406 * 拖放文件到元素或坐标位置

Callers

nothing calls this directly

Calls 1

evaluateMethod · 0.95

Tested by

no test coverage detected