And I recommend running it after dom is fully loaded:
window.onload = function() { var automator = new PageAutomator(); // Mouse eventsautomator.hover("#some-element");automator.click("#some-element", "left");automator.click("#some-element", "right");automator.scroll(200);automator.hold("#some-element", "left");automator.hold("#some-element", "right");automator.moveToPosition(200, 200);automator.moveToElement("#some-element");var position = automator.getPosition();console.log(position);// Keyboard eventsautomator.keyPress("a");automator.keyUp("a");automator.keyDown("a");automator.holdKey("a");automator.setKeyState("numlock", true);// Block inputautomator.blockInput();// Timer eventsautomator.wait(1000);automator.waitForElement("#some-element");automator.waitForMouse("pointer");// Conditionalsif (automator.ifElement("#some-element", "contains", "text")) { console.log("element contains the specified text");}// Dialogs and message boxesautomator.showNotification("This is a notification");automator.showDialog("This is a dialog");automator.showCustomDialog("<p>This is a custom dialog</p>");// Clipboardvar clipboardText = automator.getClipboardText();console.log(clipboardText);automator.setClipboardText("text to set to clipboard");automator.clearClipboard();}
window.onload = function() { var automator = new PageAutomator(); // Mouse eventsautomator.hover("#some-element");automator.click("#some-element", "left");automator.click("#some-element", "right");automator.scroll(200);automator.hold("#some-element", "left");automator.hold("#some-element", "right");automator.moveToPosition(200, 200);automator.moveToElement("#some-element");var position = automator.getPosition();console.log(position);// Keyboard eventsautomator.keyPress("a");automator.keyUp("a");automator.keyDown("a");automator.holdKey("a");automator.setKeyState("numlock", true);// Block inputautomator.blockInput();// Timer eventsautomator.wait(1000);automator.waitForElement("#some-element");automator.waitForMouse("pointer");// Conditionalsif (automator.ifElement("#some-element", "contains", "text")) { console.log("element contains the specified text");}// Dialogs and message boxesautomator.showNotification("This is a notification");automator.showDialog("This is a dialog");automator.showCustomDialog("<p>This is a custom dialog</p>");// Clipboardvar clipboardText = automator.getClipboardText();console.log(clipboardText);automator.setClipboardText("text to set to clipboard");automator.clearClipboard();}
I've also tried to make the events chainable, so you can type them out like jquery events.