Programmatically clicking a GUI button in Java Swing
Have you tried using doClick()?
Have you tried using doClick()?
Is this in Java? If so, you can use ImageIO.read( “yourImage.png” ) to get a BufferedImage. That will have a getData() method which will give you a Raster object, on which you can call getPixel. See link
If you have GTK, then you can use the gtk.gdk.Display class to do most of the work. It controls the keyboard/mouse pointer grabs a set of gtk.gdk.Screen objects.
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
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());
To get the x and y position of “any other unrelated application” you’re going to have to query the OS and that means likely using either JNI, JNA or some other scripting utility such as AutoIt (if Windows). I recommend either JNA or the scripting utility since both are much easier to use than JNI … Read more
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