This is a migrated thread and some comments may be shown as answers.

Using regular expression in Elements/Find Element

10 Answers 278 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 23 Jan 2013, 06:22 PM
Our app has many objects that change ID based on user or sometimes session.
One of these is a Submit button:
ctl00_ctl00_mastercontent_ContentPlaceHolder1_MainTemplate1_RadDock3664_C_3664_btnnewresource_input
The numbers that typically get changed are "3664".

In the Elements list I right clicked and selected Edit Element. 
Find Element is opened after selecting to locate element without connecting.
In the ID row I changed "is exactly" to "matches this regular expression"

? - Should I just replace "3664" with "*" to except multiple characters within the string like this:
ctl00_ctl00_mastercontent_ContentPlaceHolder1_MainTemplate1_RadDock3664_C_3664_btnnewresource_input
ctl00_ctl00_mastercontent_ContentPlaceHolder1_MainTemplate1_RadDock*_C_*_btnnewresource_input
Can the "?" be used in a string to accept 1 character?  Do I need to insert the wildcards in brackets?

Find Expressions were also listed in the documentation but their use is a little unclear.

Thanks,
Chris

10 Answers, 1 is accepted

Sort by
0
Mario
Telerik team
answered on 28 Jan 2013, 11:59 PM
Hello Chris,

Thank you for your interest in Test Studio and I apologize for the delay in getting back to you on this issue.

Since your application deals with dynamic ID's on a regular basis, it may be worthwhile to consider solution 1 in this article and demote/remove the id property from being used as the default means for creating an elements' primary find expression.

If the id's throughout your application are the only unique attribute associated with their respective element, then I hope you will be content with editing the search logic of every element which contains a dynamic portion in its id. Using your example, the find logic should resemble:

id 'starts with' ctl00_ctl00_mastercontent_ContentPlaceHolder1_MainTemplate1_RadDock
AND
id 'contains' _C_
AND
id 'ends with' _btnnewresource_input

With regards to using 'matches this regular expression', I apologize if our documentation has misled you in any way but 'step 5 - Advanced' in this article contains the only supported operators to be used with that expression. (Note that a * character can only be used at the end of a 'value' to signify a wild card)

Please let me know whether my suggestion helps or if you have any followup questions.

Kind regards,
Mario
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Chris
Top achievements
Rank 1
answered on 29 Jan 2013, 01:17 PM
Thanks for the info.  We'll probably demote the ID for the time being.  Our new architect is seriously looking at more consistent ID's for the GUI objects in the future.
0
dan
Top achievements
Rank 1
answered on 01 Sep 2016, 04:07 PM

Hi Mario

I have an element which can anyone of a series of ids .. advFindEFGRP0FFLD0_filterListFLD, advFindEFGRP0FFLD1_filterListFLD, advFindEFGRP0FFLD2_filterListFLD...

 

What would the wildcard be for the regular expression?

 

I've tried  id=#advFindEFGRP0FFLD?_filterListFLD

 

Thanks,

dan

0
Boyan Boev
Telerik team
answered on 06 Sep 2016, 08:08 AM
Hello Dan,

You can try this: 

ActiveBrowser.Find.ByExpression<HtmlAnchor>("id=^advFindEFGRP0FFLD");

It will find every element which ID starts with "advFindEFGRP0FFLD".

Let me know if that helps.

Regards,
Boyan Boev
Telerik by Progress
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Renjila
Top achievements
Rank 1
answered on 06 Aug 2018, 08:06 AM

As I cannot rely on the exact id for elements in  our application, I tried to edit the element as follows :

1. tagname 'is exactly' a 

2. id 'matches this regular expression'  "splitbutton-([0-9]+)$"

I gave the wait logic which is

bool expextedValue = true;

Pages.Https1013129.Splitbutton1039Link.Wait.ForCondition((a_0, a_1) => (((ArtOfTest.WebAii.Controls.HtmlControls.HtmlAnchor)(a_0)).IsVisible() == expextedValue), false, null, 30000);

 

This step failed on running the test as it couldn't find the element.

 

Then I tried the following method by editing the find logic code as follows

HtmlFindExpression expression = new HtmlFindExpression("id=^splitbutton-([0-9]+)$", "tagname=a");
ActiveBrowser.WaitForElement(expression, 10000, false);

 

This also didn't work.

Please let me know what I missed in both cases.

Thanks in advance

Renjila

 

0
Elena
Telerik team
answered on 08 Aug 2018, 02:07 PM
Hello Renija,

Thank you for sharing details about your difficulties. 

Could you please use hash sign (#) in front of the regular expression as this is the supported operator for this kind of identification. I hope this will work for you! 

Regards,
Elena Tsvetkova
Progress Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Renjila
Top achievements
Rank 1
answered on 15 Aug 2018, 07:20 AM

Thank you for your inputs!

Regards,

Renjila

0
Elena
Telerik team
answered on 15 Aug 2018, 01:39 PM
Hello Renjila,

Thank you for getting back to me. I am glad to know the resource was useful for you! 

Regards,
Elena Tsvetkova
Progress Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Madhusmita
Top achievements
Rank 1
answered on 10 Oct 2018, 10:12 AM

Hi,

I have an id as C1__C2__WORKINGELEMENTS[1].ANSWERS[1].CURRENTVALUEINCLVAT where the C2 part the number can be anything so i wanted to use a better way for identifying the element.

I tried id end with WORKINGELEMENTS[1].ANSWERS[1].CURRENTVALUEINCLVAT and id starts with C1__C*__ but it does not identify. How can I make this work?

 

0
Elena
Telerik team
answered on 15 Oct 2018, 08:20 AM
Hello Madhusmita,

Thank you for the details. 

There are few options which should cover the described scenario. Please find these below: 

- You could modify the find expression for the clause 'id starts with' to use the string partially and set it to 'id contains ~C1__C'.

- If you need to explicitly use 'starts with' that combination, I guess the scenario could be covered with 'id starts with C1__C'.

- And the last option is to use regular expression - to mark a string in Test Studio find expression which will be used as a regular expression, you need to add a hash sign at the beginning. In other words it should look like 'id matches the regular expression #C1__C*__. 

I hope any of these will be suitable for you. In case you need further assistance please let me know. 

Regards,
Elena Tsvetkova
Progress Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Chris
Top achievements
Rank 1
Answers by
Mario
Telerik team
Chris
Top achievements
Rank 1
dan
Top achievements
Rank 1
Boyan Boev
Telerik team
Renjila
Top achievements
Rank 1
Elena
Telerik team
Madhusmita
Top achievements
Rank 1
Share this question
or