Skip to content

Commit

Permalink
fixed element scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
dikwickley committed Jul 18, 2024
1 parent a1b465a commit 3fdfc79
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions lib/transport/selenium-webdriver/method-mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1328,43 +1328,36 @@ 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".');
}

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;
},

Expand Down

0 comments on commit 3fdfc79

Please sign in to comment.