ui-automation icon indicating copy to clipboard operation
ui-automation copied to clipboard

Insert text

Open stdex opened this issue 6 years ago • 4 comments

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?

stdex avatar Jan 06 '19 23:01 stdex

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

mmarquee avatar Jan 07 '19 12:01 mmarquee

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.

stdex avatar Jan 13 '19 12:01 stdex

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 avatar Jan 14 '19 13:01 markhumphreysjhc

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

markhumphreysjhc avatar Jan 14 '19 13:01 markhumphreysjhc