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

Method scrollTo

lib/helper/Puppeteer.js:920–939  ·  view source on GitHub ↗

* {{> scrollTo }}

(locator, offsetX = 0, offsetY = 0)

Source from the content-addressed store, hash-verified

918 * {{> scrollTo }}
919 */
920 async scrollTo(locator, offsetX = 0, offsetY = 0) {
921 if (typeof locator === 'number' && typeof offsetX === 'number') {
922 offsetY = offsetX
923 offsetX = locator
924 locator = null
925 }
926
927 if (locator) {
928 const el = await this._locateElement(locator)
929 if (!el) {
930 throw new ElementNotFound(locator, 'Element to scroll into view')
931 }
932 await el.evaluate(el => el.scrollIntoView())
933 const elementCoordinates = await getClickablePoint(el)
934 await this.executeScript((x, y) => window.scrollBy(x, y), elementCoordinates.x + offsetX, elementCoordinates.y + offsetY)
935 } else {
936 await this.executeScript((x, y) => window.scrollTo(x, y), offsetX, offsetY)
937 }
938 return this._waitForAction()
939 }
940
941 /**
942 * {{> seeInTitle }}

Callers 6

scrollPageToTopMethod · 0.45
scrollPageToBottomMethod · 0.45
testsFunction · 0.45

Calls 6

_locateElementMethod · 0.95
executeScriptMethod · 0.95
_waitForActionMethod · 0.95
getClickablePointFunction · 0.85
evaluateMethod · 0.80
scrollIntoViewMethod · 0.45

Tested by

no test coverage detected