MCPcopy
hub / github.com/codeceptjs/CodeceptJS / moveCursorTo

Method moveCursorTo

lib/helper/Puppeteer.js:825–852  ·  view source on GitHub ↗

* {{> moveCursorTo }}

(locator, offsetX = 0, offsetY = 0)

Source from the content-addressed store, hash-verified

823 * {{> moveCursorTo }}
824 */
825 async moveCursorTo(locator, offsetX = 0, offsetY = 0) {
826 let context = null
827 if (typeof offsetX !== 'number') {
828 context = offsetX
829 offsetX = 0
830 }
831
832 let el
833 if (context) {
834 const contextEls = await findElements.call(this, this.page, context)
835 assertElementExists(contextEls, context, 'Context element')
836 const els = await findElements.call(this, contextEls[0], locator)
837 if (!els || els.length === 0) {
838 throw new ElementNotFound(locator, 'Element to move cursor to')
839 }
840 el = els[0]
841 } else {
842 el = await this._locateElement(locator)
843 if (!el) {
844 throw new ElementNotFound(locator, 'Element to move cursor to')
845 }
846 }
847
848 // Use manual mouse.move instead of .hover() so the offset can be added to the coordinates
849 const { x, y } = await getClickablePoint(el)
850 await this.page.mouse.move(x + offsetX, y + offsetY)
851 return this._waitForAction()
852 }
853
854 /**
855 * {{> focus }}

Calls 4

_locateElementMethod · 0.95
_waitForActionMethod · 0.95
getClickablePointFunction · 0.85
assertElementExistsFunction · 0.70

Tested by

no test coverage detected