How do you pass variables to Object Repository Screen Selector Variable from a Coded Workflow?

Hello, Good Morning, Good Evening and Good night. Hope you doing well. I need some help.

I got a Application and Screen instance in Object Repository that rely on a Variable called urlMainPage . Since I am working on Coded Workflows I am a bit confused on how to pass it down at Runtime.

This is my code:

[Workflow]
        public System.String Execute
            (System.String urlMainPage=@"https://example.com/")
        {
          // Browser Settings
          var initMainBrowserSettings = new TargetAppOptions
            {
                InteractionMode = NInteractionMode.Simulate,
                OpenMode = NAppOpenMode.Always,
                Variables = new Dictionary <string, string>
                {
                    {"urlMainPage", urlMainPage}
                }
            };
           // Main Page open Browser
           var selfMainScreen = Descriptors.Chrome_App.Main_Page;
           var mainScreen = uiAutomation.Open(selfMainScreen,initMainBrowserSettings);
         }

I have seen other posts that use it with ClickOptions variable, but for some reason I can’t get it to work on an TargetAppOptions variable, I double checked for the namings in the Selector for any typos or anything, but nothing was wrong.

Thats it, Thank you in advance.

Edit:

Thanks everyone for the suggestions, I think that object repository must have some limitation with .Open() or other activities, I mean, why in the world would it work with a ClickOptions() variable, but not with .Open().

I can definitely figure a work around for this, but in the Long Term run, following the rules of maintenance of High Enterprise code, I would have to edit the Object Repository AND the coded workflow (since the argument is coming from Config.xlsx file)

Anyways, thanks everyone for the help.
I will let you know via this post if something works.

Hi @mla_rpa ,
The issue is that Object Repository variables are not always resolved from TargetAppOptions.Variables in Coded Workflows. While passing variables through ClickOptions works for some activities, Open() may not automatically replace the Object Repository variable from the Variables dictionary.

A common approach is to:

  • Pass the URL directly when opening the browser:
    uiAutomation.Open(urlMainPage, initMainBrowserSettings);
  • Or define the URL dynamically in code and avoid relying on an Object Repository variable for the application instance.
  • Also verify that the variable name in the Object Repository selector is exactly urlMainPage (case-sensitive).

If the variable is still not being resolved, it is likely a current limitation of TargetAppOptions.Variables with Object Repository application descriptors in Coded Workflows. In that case, create the browser/application dynamically in code and pass the URL directly rather than through the Object Repository variable.
Thanks

Hi @mla_rpa

Your approach is correct. For Coded Workflows, you can pass the Object Repository variable through TargetAppOptions.Variables like this:

var options = new TargetAppOptions
{
    Variables = new Dictionary<string, string>
    {
        { "urlMainPage", urlMainPage }
    }
};

var mainScreen = uiAutomation.Open(
    Descriptors.Chrome_App.Main_Page,
    options
);

Just make sure the variable name urlMainPage is exactly the same in the Object Repository selector.

If it still doesn’t work, check that urlMainPage is actually defined as a selector variable in the Object Repository and not hardcoded as a string.

Hi @mla_rpa,

Your approach looks correct in principle. For Object Repository selector variables in a Coded Workflow, make sure that the variable is defined at the Application/Screen level and that the name matches exactly (urlMainPage).

Since you are opening the application using TargetAppOptions, passing the value through the Variables dictionary should be the right approach:


var initMainBrowserSettings = new TargetAppOptions
{
    InteractionMode = NInteractionMode.Simulate,
    OpenMode = NAppOpenMode.Always,
    Variables = new Dictionary<string, string>
    {
        { "urlMainPage", urlMainPage }
    }
};

Also, try checking whether the selector variable is actually being used in the Application descriptor/URL selector that Descriptors.Chrome_App.Main_Page refers to. If the variable is only defined in another screen or descriptor, it may not be available when opening the application.

You can also test with a hardcoded value first to confirm that the variable binding is working.

Hope this helps!

Hi @mla_rpa

For an Object Repository selector variable, the variable needs to be defined in the workflow and referenced in the descriptor using {{urlMainPage}}. UiPath supports variables in Object Repository descriptors, including when using coded automations.

Your approach with TargetAppOptions.Variables looks reasonable. I would also verify that urlMainPage is added as a selector variable in the Object Repository descriptor itself, and that the variable name matches exactly.

For example, the selector should contain something like:

<... url='{{urlMainPage}}' ... />

If it still doesn’t resolve through TargetAppOptions, it may be worth trying the descriptor/string-based approach or checking the UiPath.CodedWorkflows and UI Automation package versions.

Hope this helps!

Hi Jasmin_Bar.

Thank you for your insight and kindness. I am still a bit confused on this code:

uiAutomation.Open(urlMainPage, initMainBrowserSettings);

Although this would work for this exact case, would it work for other activities such as .Attach() or .Click()?

I thought that in C# Coded Workflows for UI Automation you MUST reference an Object Repository instance (App, Screen, UiObjects).

I am thinking of making the automation open the App from a low code workflow and then use .Attach in Coded Workflow. maybe something about C# Coded Workflows not rendering at runtime or something, I don’t really know.

I was wondering how you would approach this.

Thank you kindly

@mla_rpa

Welcome to the community

You need not explicitly assign the variable..declaring one with the requiredvalue and exact name shouldautomatically pull the variablevalue

Cheers

Hello, I may be missing something, could you give me an example, or rather, like a template code of what you mean, with the .Open() and the Object Repository instance with a variable?

do you literally mean:

string urlMainPage = "https://example.com/";

before the .Open(), cuz that didn’t work for sure

Sorry in advance, im pretty sure it has to be one small technical thing