2

I'm new to the world of C# automation so apologies if this is obvious. My colleagues and I work frequently within an app written in Java, and I'm looking to automate some of the tasks. However, I can't seem to identify any of the elements (various menus, textboxes, etc.) within the Java windows using the tools I'm aware of (Inspect and Spy++). Nothing within the main "window" of the app shows up in Inspect (just the title bar and its' children).

I've gotten the automation working by using P/Invoke SendInput commands to click on the various parts of the window I need to click on (based on x/y coordinates) and enter text as if it's coming from the keyboard. However, this seems a bit ... fiddly. I'd feel better using this if I could formalize element names instead of just sending mouseclick instructions via code, is there a way to do this? For example with something like the Windows.Automation library when I don't have the element IDs?

user2864740
  • 60,010
  • 15
  • 145
  • 220
Kevin Pope
  • 2,964
  • 5
  • 32
  • 47
  • 2
    Java Swing controls are lightweight (much like WPF controls) - meaning they are rendered "in" Java and *do not [necessarily] have a native component* (eg. window/handle) as the original AWT controls did. This is why Inspect/Spy++ do not work [well] for Swing (or WPF) applications. There might be a special "SwingSpy++", but.. – user2864740 Mar 02 '15 at 21:49
  • @Kevin Pope http://stackoverflow.com/questions/28589908/click-on-button-in-another-program-findwindow-c-sharp/28590320#28590320 – Dn24Z Mar 02 '15 at 21:58
  • @Dn24Z - thanks for that, but I've already done the P/Invoke solution, was looking for something that was less reliant on coordinates. – Kevin Pope Mar 02 '15 at 22:05
  • @Kevin Pope try using keyboard or implement translator pattern in your java application, no other way. – Dn24Z Mar 02 '15 at 22:07
  • @Kevin Pope that is assuming you have access to source code of java application. – Dn24Z Mar 02 '15 at 22:10
  • @Dn24Z - yeah, unfortunately that's the problem. It's a 3rd party application so I can't get the source. – Kevin Pope Mar 02 '15 at 22:11
  • @Kevin Pope I am afraid that it is impossible if a developer didn't have that kind of access in mind, when developing an application. Everything else will be coordinates or keyboard input. – Dn24Z Mar 02 '15 at 22:15

1 Answers1

0

TestStack.White framework written in C# should help you. It's based on UI Automation API and should see any lightweight controls like WPF ones.

Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78