How to make selectors ignore case sensitivity?

Hi,

So my use case is trying to select a username in a list of users on a website. Some usernames are lower case while others are upper case.

So currently if the user wants to search for cyoung but the result is CYoung, the automation will return that it has not been found.

Is there a way to overcome this without cycling through the whole table on the website and testing each one by putting the attribute to lower case?

Hope this makes sense!

1 Like

You can achieve this using the IndexOf Method with the StringComparison.CurrentCultureIgnoreCase argument.

See attached working example.

Main.xaml (5.3 KB)

That does exactly what I need it to do, but how would I use that function in a selector field - for example, in a click activity?

You could put the click inside the If statement in the workflow I provided, so if a match is found, click on it. Otherwise, continue. Is that what you mean?

Not quite - so I need to be able to click on “john”, “John”, “JOHN” & “JoHn”.

Using an if statement, or switch, I would have to cover every possible scenarios of upper/lower case, which gets ridiculous if i wanted to click on a sentence for example.

Does that make sense?

Hi @CYoung do you have duplicates in your usernames like if u search for cYoung does it gives a single result or multiple results like cYoung,cyoung,etc, in that case you can use the get attribute activity in this case it will be "aa " name and store that as a variable and pass it to the selector which you are trying to use.

@WhenCutEsh has a good answer here. you need to grab the aaname attribute and do an analysis for a match using the If statement flow I provided. then, if a match is found against your input name (John), you know it should be selected.

The only thing with this solution is that because the username is in a table and I do not know the row number, I will have to cycle through the whole table.

I know this way will work, but is there a way to do this while avoiding a loop through the whole table?

Yes. I have encountered the same issue on a web application I was automating which required selecting certain rows based on the value in a certain column.

I first used the FindChildren Activity on the table and filtered on the column I needed (e.g. <webctrl tag=‘TD’ aaname=‘Name’). This produces a list of UiElements that meet the criteria, in this case just the column I wanted. So you have access not only to the value of each row in that column, but also the selector. I created a datatable from this list with values on one column (aaname attributes) and full selectors on the other.

You may still have to use a for each loop here to cycle through all values but it is quick because the data is not being gathered each time, its all done in one sweep.

So you cycle through that datatable using a For Each and with every match of aaname (using my workflow provided with the IF statement which ignores case) you get the corresponding selector and click that.

Sorry I can’t provide a working example but this would be a way to analyse the values but ensure the selector is available at the same time to then click or not click, depending on the output of that analysis.

2 Likes

thank you, i think this is the quickest solution at the moment

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.