How do I move the mouse instantly in Selenium WebDriver Chrome? Node.js

ActionChains only moves the mouse smoothly from (0, 0) to the position.

I tried setting the parameter ‘duration’ in actions.move to 0, but that will make the mouse movement only smoother.
I want the pointer to be instantly at the new position, not moved smoothly, just instantly on the new position.

My use case for ActionChains is a remote control scenario, where the other end moves their mouse and sees the page and also replicates mouse movement on the browser side.

Reproducible code:

const { Builder, Origin } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
let chromeOptions = new chrome.Options();
chromeOptions.addArguments('--window-size=800,600');
async function createSession() {
    let driver = await new Builder()
    .forBrowser('chrome')
    .setChromeOptions(chromeOptions)
    .build();
    await driver.get("https://www.selenium.dev/selenium/web/mouse_interaction.html");
    let actions = driver.actions({async: true});
    return [driver, actions]
}
function delay(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
async function main() {
    const test = await createSession();
    while (true) {
        await delay(5000);
        await test[1].move({x: Math.floor(Math.random()*300), y: Math.floor(Math.random()*300), origin: Origin.VIEWPORT}).perform();
    }
}
main();

If you scroll down, I saw the Absolute location change a lot of times under a second, which means it is being smoothly moved, this script moves the mouse randomly every 5 seconds, not 1 second.

Read more here: Source link