How to simulate a real mouse click using java?

Well I had the same exact requirement, and Robot class is perfectly fine for me. It works on windows 7 and XP (tried java 6 & 7). public static void click(int x, int y) throws AWTException{ Robot bot = new Robot(); bot.mouseMove(x, y); bot.mousePress(InputEvent.BUTTON1_DOWN_MASK); bot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); } May be you could share the name of the … Read more

File Upload using Selenium WebDriver and Java Robot Class

This should work with Firefox, Chrome and IE drivers. FirefoxDriver driver = new FirefoxDriver(); driver.get(“http://localhost:8080/page”); File file = null; try { file = new File(YourClass.class.getClassLoader().getResource(“file.txt”).toURI()); } catch (URISyntaxException e) { e.printStackTrace(); } Assert.assertTrue(file.exists()); WebElement browseButton = driver.findElement(By.id(“myfile”)); browseButton.sendKeys(file.getAbsolutePath());

Convert String to KeyEvents

I’m basically using a glorified switch statement. Simple and fast: import static java.awt.event.KeyEvent.*; public class Keyboard { private Robot robot; public static void main(String… args) throws Exception { Keyboard keyboard = new Keyboard(); keyboard.type(“Hello there, how are you?”); } public Keyboard() throws AWTException { this.robot = new Robot(); } public Keyboard(Robot robot) { this.robot = … Read more