Get UiElement From Selector in Coded Workflow

Hi all,

How can I get a UiElement from a given selector in a Coded Workflow? Essentially I am looking to reproduce the functionality of the ‘Check App State’ activity and the ‘Output element’ output. My end goal is to be able to get a UiElement and set the attribute of it using the UiElement.Set method. Is this the correct method?

This is what I have so far:

public void Execute()
{
    TargetAppModel appModel = new TargetAppModel();
    appModel.WithUrl("https://www.google.com/", "<html app = 'msedge.exe'/>", NBrowserType.Edge);

    // Get the search box element
    TargetAnchorableModel target = Target.FromSelector("<webctrl id='APjFqb' tag='TEXTAREA' />");
    
    RuntimeTarget runtimeTarget = targetApp.GetRuntimeTarget(target);
    
    UiElement element = targetApp.GetUiElement(runtimeTarget);

    element.Set("attribute", "value");
}

targetApp.GetUiElement(runtimeTarget) returns the element of the browser window instead of the target, and element.Set(“attribute”, “value”) fails with the following exception:

image

Thanks,

Tim

Also, is there any documentation for the UI Automation APIs outside of Activities - UI Automation APIs (uipath.com)? This document is very light.

How are people learning to use UI activities in Coded Workflows without more comprehensive documentation?

Thanks,

Tim

Bump. Can anyone help me with this?

Bump. Are there any experts in Coded Workflows that can help me with this?

Hi @Timothy_Morris

not an expert but I assume GetRuntimeTarget should be added after an open or attach

image

public void Execute()
        {
            TargetAppModel appModel = new TargetAppModel();
            
            appModel.WithUrl("https://www.google.com/", "<html app = 'chrome.exe' title='Google' />", NBrowserType.Chrome);

            TargetAnchorableModel target = Target.FromSelector("<webctrl id='APjFqb' tag='TEXTAREA' />");
            
            var home = uiAutomation.Open(appModel);
            
            home.TypeInto(target,"Hello world");
            home.KeyboardShortcut(target, "[d(hk)][k(enter)][u(hk)]");
            var ok = home.GetRuntimeTarget(target);
            
            Console.WriteLine("breakpoint");          
        }

Although I dont see elements in appModel or target

maybe try checking with an if condition if your element is null or not

image
image

Thanks for the response.

In my example I forgot to include that I was using uiAutomation.Open().

Can anyone help? Does anyone know how to get a UiElement on a page in a Coded Workflow?

Thanks,

Tim

UiElement ele_out_LookedFor = null;
WorkflowInvoker.Invoke(new UiPath.Core.Activities.WaitUiElementAppear
{
ContinueOnError = true,
Target ={
Selector = strSelectorToLookFor,
TimeoutMS = iMillisecondsToSearch,
WaitForReady = WaitForReady.NONE
},
WaitActive = false,
WaitVisible = false,
Result = new OutArgument(ctx => ele_out_LookedFor)
});

This is how I do it in a coded source file. The code is not complete due to reasons. Still it will give a clear view of how I did it.


            anEl.Selector = new Selector("[A SELECTOR]");

            GetChildrenOptions gco = new GetChildrenOptions();
            gco.SelectorFilter = "[A SELECTOR FILTER]";
            gco.Timeout = 3;
            gco.Recursive = true;
            var c = anAPP.GetChildren(UiPath.UIAutomationNext.API.Models.Target.FromSelector("[A SELECTOR]"), gco);

            foreach (RuntimeTarget rt in c)
            {