mmarquee / ui-automation

Java wrapper for ms-uiautomation
https://mmarquee.github.io/ui-automation/
Apache License 2.0
111 stars 54 forks source link

Insert text #99

Open stdex opened 5 years ago

stdex commented 5 years ago

Hello.

If I need implement something like this:
https://docs.microsoft.com/nl-nl/dotnet/framework/ui-automation/add-content-to-a-text-box-using-ui-automation

As I see I need method AutomationElement.TryGetCurrentPattern (with ValuePattern object) and method SendWait from System.Windows.Forms.SendKeys)

How can I do this?

mmarquee commented 5 years ago

Essentially, but the library will do much of the work for you, so you would have to do something like this (which is hidden in one of the example programs)

        String text = applicationWindow.getEditBox(
                Search.getBuilder(1).build()).getValue();
        logger.info("Text for edit box 1 is " + text);

        applicationWindow.getEditBox(
                Search.getBuilder(1).build()).setValue("Hi");
        logger.info("Text for edit box 1 is now " +
                applicationWindow.getEditBox(
                        Search.getBuilder(1).build()).getValue());`

This gets the editbox, and does a setValue for it.

Is that what you mean? There might be better examples in the Develop branch, if not, Ill try to add some for each control

stdex commented 5 years ago

And how I can get Window object of current focused editbox? I try to get it from Element (automation.getFocusedElement()), but it looks like I cannot do it this way.

markhumphreysjhc commented 5 years ago

Only one element has focus, so it's an overall thing, a quick snippet I've just looked ...

Element focused = automation.getFocusedElement();
String v = focused.getClassName();
logger.info("Focused class-name is : " + v);
markhumphreysjhc commented 5 years ago

The Element here is a 'raw' thing, so you'd have to know it was an EditBox (for example), and create an EditBox object to get at the EditBox specific functions, and Patterns