diff --git a/lib/transport/selenium-webdriver/method-mappings.js b/lib/transport/selenium-webdriver/method-mappings.js index fd47042ef..627910040 100644 --- a/lib/transport/selenium-webdriver/method-mappings.js +++ b/lib/transport/selenium-webdriver/method-mappings.js @@ -1328,22 +1328,23 @@ module.exports = class MethodMappings { const rect = await element.getRect(); const centerX = parseInt(rect.x + rect.width / 2); const centerY = parseInt(rect.y + rect.height / 2); - let endX = centerX; - let endY = centerY; + + let scrollY = centerY; + let scrollX = centerX; // Determine the final coordinates based on the direction and amount switch (direction.toLowerCase()) { case 'up': - endY = centerY - amount; + scrollY = Math.min(scrollY, amount); break; case 'down': - endY = -1 * (centerY + amount); + scrollY = -1 * Math.min(scrollY, amount); break; case 'left': - endX = centerX - amount; + scrollX = Math.min(scrollX, amount); break; case 'right': - endX = centerX + amount; + scrollX = -1 * Math.min(scrollX, amount); break; default: throw new Error('Invalid direction. Use "up", "down", "left", or "right".'); @@ -1351,20 +1352,12 @@ module.exports = class MethodMappings { await this.driver.actions({async: true}).insert( pointer1, - pointer1.move({x: centerX, y: 100}), + pointer1.move({origin: element}), pointer1.press(), - pointer1.move({duration: 1000, origin: 'pointer', y: endY}), + pointer1.move({duration: 1000, origin: element, y: scrollY, x: scrollX}), pointer1.release() ).perform(); - // await this.driver.actions({async: true}).insert( - // pointer1, - // pointer1.move({ x: 100, y: 500}), - // pointer1.press(), - // pointer1.move({duration: 1000, origin: 'pointer', y: -500}), - // pointer1.release() - // ).perform(); - return null; },