#FeatureBlog - 19.10 - Using regular expression (Regex) in the selector attributes

Hi,

How can I use this in browser? Can someone help me?

Nice information. :+1:

Hi! @loginerror
Can’t we use this with java applications?
I can’t make it validated in any case.

<java idx='1' name='Grup Yetkilisi İş Takip Listesi' role='internal frame' />
<java name='\d+' matching:name='regex' role='push button' />

can it be defualt match regex

Hi @sarikayaebru,

Did you make it to work with java selector?

Thanks

Hi, @loginerror
I’m trying using this feature in UiPath 2019.10.3 but I can’t as I am getting this error. Could you please help?

Hi @AhmedEbrahim

Could you try with INC\d+?

Please also make sure that your UiAutomation package is up to date.

2 Likes

thanks @loginerror I updated UiAutomation package and works fine now.

1 Like

nice trick

Nope, unfortunately.

how can I use OR condition in regular expression and use that regex in Selectors.

in My case I want to click on an object which has
title=^Archiv* OR ^Search*
how can I achieve this.
I am using title=’^Archive*|^Search*’
is this correct?

Hi @sanjeev.sapre

I have a Regex MegaPost aimed at new users. Hopefully this can help you.

Regex help tutorial MEGAPOST – Making your first Regex post, Reusable Regex Patterns, Regex Troubleshooting, Sample Workflow and more

Cheers

1 Like

I’m having a need to use Regex Selectors. But I’m unable to make the selector return multiple elements. It returns just the first match. I have confirmed that all selectors are identical and can be captured by matching with an expression on parentid attribute.

I have tested it on an online regex editor, and I see that the expression matches multiple selectors:

But when the automation runs, only the first match element is returned.

What am I doing wrong?

thanks!

@AndyMenon - what is the code your are using for print the regex output?

Hi @prasath17,

I’m using a GetText activity and returning the value into a variable and printing it out.

Thanks

@prasath17 - did this answer your question? If not I can send screen grabs of what I’m trying to do when I get back to my desk.

thanks

@AndyMenon - That would be helpful.

I cannot show my actual business problem, but here is a similar situation I’m trying to replicate in public using Google finance. I’m trying to extract text from the 6 DIVs.

The first step for me is to have a REGEX selector that can match all of the 6 DIVs. Once I have those, I can loop through each of the inside text and use standard Regex operations to extract parts of the information I need.

Here is the Selector for the first DIV #1 and the last DIV #6. As you can see, that they fit a pattern.

<webctrl css-selector='body&gt;c-wiz&gt;div&gt;div&gt;div&gt;div&gt;div&gt;c-wiz&gt;div&gt;section&gt;div&gt;a&gt;div&gt;div' idx='1' parentid='yDmH0d' tag='DIV' />

<webctrl css-selector='body&gt;c-wiz&gt;div&gt;div&gt;div&gt;div&gt;div&gt;c-wiz&gt;div&gt;section&gt;div&gt;a&gt;div&gt;div' idx='6' parentid='yDmH0d' tag='DIV' />

I have confirmed this with a basic text comparison as shown below, both selectors are the same except for their idx values:

And here is my Regex Selector - in my previous post I showed that the regex does seems like it is working when I test it in a Regex Editor and it also validates in UiExplorer.

<webctrl css-selector='body&gt;c-wiz&gt;div&gt;div&gt;div&gt;div&gt;div&gt;c-wiz&gt;div&gt;section&gt;div&gt;a&gt;div&gt;div' parentid='(yDmH0d)' tag='DIV' matching:parentid='regex'/>

The Automation does not fail, it runs and returns text only from the first matching DIV ( the BETW Stock ticker symbol) . I was expecting it to return a large text containing text from all of the DIVs that could later be split and processed.

image

Thanks and let me know if I’m missing something.

Ok, so this is interesting and confusing now. And now I’m wondering if I’ve understood this entire subject correctly! I tried an alternate approach, and this time I got a failure.

I tried to write a Regex on the idx attribute of the selector to look for all tags between idx=‘1’ and idx=‘6’ like so:

<webctrl css-selector='body&gt;c-wiz&gt;div&gt;div&gt;div&gt;div&gt;div&gt;c-wiz&gt;div&gt;section&gt;div&gt;a&gt;div&gt;div' idx='[1-6]{1}' parentid='yDmH0d' tag='DIV' matching:idx='regex' />

But I can’t figure out why the Robot is looking for idx=‘0’ when I have specified the range [1-6] in my Regex. This is causing a failure obviously .

But the good thing is it knows that there are 6 elements that can be matched. If that is so, why is my earlier Regex on parentid not working? And if the Robot knows about the 6 other matches, why is it wasting it’s time by trying to find idx=‘0’ that it is not supposed to look for in the first place, and then failing?

image

@AndyMenon

If you want all elements matching your selector, use FindChildren activity to get them. If your selector can match multiple elements and you’re relying on an activity expected to return one element, you’ll get the first match only.

1 Like