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

Method scrollTo

lib/helper/Playwright.js:1674–1694  ·  view source on GitHub ↗

* {{> scrollTo }}

(locator, offsetX = 0, offsetY = 0)

Source from the content-addressed store, hash-verified

1672 * {{> scrollTo }}
1673 */
1674 async scrollTo(locator, offsetX = 0, offsetY = 0) {
1675 if (typeof locator === 'number' && typeof offsetX === 'number') {
1676 offsetY = offsetX
1677 offsetX = locator
1678 locator = null
1679 }
1680
1681 if (locator) {
1682 const el = await this._locateElement(locator)
1683 assertElementExists(el, locator, 'Element')
1684 await el.scrollIntoViewIfNeeded()
1685 const elementCoordinates = await clickablePoint(el)
1686 await this.executeScript((offsetX, offsetY) => window.scrollBy(offsetX, offsetY), {
1687 offsetX: elementCoordinates.x + offsetX,
1688 offsetY: elementCoordinates.y + offsetY,
1689 })
1690 } else {
1691 await this.executeScript(({ offsetX, offsetY }) => window.scrollTo(offsetX, offsetY), { offsetX, offsetY })
1692 }
1693 return this._waitForAction()
1694 }
1695
1696 /**
1697 * {{> seeInTitle }}

Callers 2

scrollPageToTopMethod · 0.45
scrollPageToBottomMethod · 0.45

Calls 5

_locateElementMethod · 0.95
executeScriptMethod · 0.95
_waitForActionMethod · 0.95
clickablePointFunction · 0.85
assertElementExistsFunction · 0.70

Tested by

no test coverage detected