MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / scrollTo

Method scrollTo

lib/helper/WebDriver.js:1916–1950  ·  view source on GitHub ↗

* {{> scrollTo }} *

(locator, offsetX = 0, offsetY = 0)

Source from the content-addressed store, hash-verified

1914 *
1915 */
1916 async scrollTo(locator, offsetX = 0, offsetY = 0) {
1917 if (typeof locator === 'number' && typeof offsetX === 'number') {
1918 offsetY = offsetX
1919 offsetX = locator
1920 locator = null
1921 }
1922
1923 if (locator) {
1924 const res = await this._locate(withStrictLocator(locator), true)
1925 assertElementExists(res, locator)
1926 const elem = usingFirstElement(res)
1927 const elementId = getElementId(elem)
1928 if (this.browser.isMobile && !this.browser.isW3C) return this.browser.touchScroll(offsetX, offsetY, elementId)
1929 const location = await elem.getLocation()
1930 assertElementExists(location, locator, 'Failed to receive', 'location')
1931
1932 return this.browser.execute(
1933 function (x, y) {
1934 return window.scrollTo(x, y)
1935 },
1936 location.x + offsetX,
1937 location.y + offsetY,
1938 )
1939 }
1940
1941 if (this.browser.isMobile && !this.browser.isW3C) return this.browser.touchScroll(locator, offsetX, offsetY)
1942
1943 return this.browser.execute(
1944 function (x, y) {
1945 return window.scrollTo(x, y)
1946 },
1947 offsetX,
1948 offsetY,
1949 )
1950 }
1951
1952 /**
1953 * {{> moveCursorTo }}

Callers 2

scrollPageToTopMethod · 0.45
scrollPageToBottomMethod · 0.45

Calls 5

_locateMethod · 0.95
withStrictLocatorFunction · 0.85
usingFirstElementFunction · 0.85
getElementIdFunction · 0.85
assertElementExistsFunction · 0.70

Tested by

no test coverage detected