How to read value of a windows control?

How do I read value of a windows control? I am working with Dynamics Navision software and want to read a sum value that is in the footer section of a window. I am able to identify the object selector but how do I read the value of the object and assign to a variable?

Thanks in advance.

1 Like

Hi @peke_robot,

You can do it 2 ways:

1st (if the application allows to copy the value): double-click on the UI control, copy the value using Ctrl-c, save to a variable using Clipboard action

2nd - use a UI selector with getText method in a custom action

Here is the sample custom action, you need to insert the variable name and the selector.

@CustomScriptAction(
    output = 'variable_name'
)

def customScript() {

    variable_name = RString.of($("object_selector").getText())

}
1 Like

Perfect - just the thing I was looking for!

1 Like

Hello,

I am having trouble passing the object_selector as input variable for the custom script. What is the appropriate format for the input in the 2nd example above?

When the object selector is hard coded into the script this works out fine.

Thanks!

@peke_robot you need to use it the same way as in other recorder actions, with dollar sign and curly brackets.

@CustomScriptAction(
    input =  ['selector'],
    output = 'text'
)

def customScript() {

    text = RString.of($("${selector}").getText())

}

1 Like

Ah ok – naturally this way!! Thanks!!

1 Like

Thanks these worked out nicely.

Is there any way to do the reverse ie. use putText(), similarly as with web elements?

There is, you can do it using method setText.
I actually just posted a sample script for that in another topic yesterday :slightly_smiling_face:

1 Like

Perfect - as this enables much more robust implementations in comparison to keyboard text entry.

1 Like

Hi @ashapkina this isn’t quite working for me. It’s giving me a blank output for an object that has a text value. I’m testing it on a file explorer window, and the custom script is nested within a window action. Is there something I’m missing?

Can the Inspector in the Studio see this element? And if it does, does it have the Text attribute?

Yes and yes. It seems to be pretty inconsistent. I can get to work for some elements but not others - all of which have text attributes.

Hi @ashapkina were you able to look into this at all? Here’s an example:
Code I’m using:

@CustomScriptAction(
    input =  ['str_task_selector'],
    output = 'str_number_of_assigned_tasks'
)

def customScript() {

    str_number_of_assigned_tasks = RString.of($("${str_task_selector}").getText())

}

Default values:
str_task_selector = [CLASS:ListItem;REGEXPNAME:Tasks Assigned to BOTS]
str_number_of_assigned_tasks = NA

From Inspector:
image

My selector value works fine when using it with a mouse click action so it’s valid and you can see that the element has a text value. The output is blank even though the default value is “NA” so it seems to be doing something.

Any ideas? Thanks!

Hi @wwylie sorry, just got back in the office and looking into it.

Do you read the text from Excel or another application? Please share the version so we test it.

Is the name of the element always the same as the text? If it is, try reading the value of the “Name” attribute. Here is a sample script.

@CustomScriptAction(
    input =  ['str_task_selector'],
    output = 'str_number_of_assigned_tasks'
)

def customScript() {

    str_number_of_assigned_tasks = RString.of($("[CLASS:ListItem;REGEXPNAME:Tasks Assigned to BOTS]").getAttribute('Name'))
 
}

Let me know if it doesn’t work either.

1 Like

This worked, thank you!!

1 Like

I’m glad it helped @wwylie. Did you have this issue in Excel or some other application?

It was a different application. Also “getAttribute(‘Text’)” worked when “getText()” did not.

1 Like

Thank you @wwylie we’ll try to reproduce such issue.