Using regular expression in Elements/Find Element

11 posts, 0 answers
  1. Chris
    Chris avatar
    4 posts
    Member since:
    Jun 2012

    Posted 23 Jan 2013 Link to this post

    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
  2. Mario
    Admin
    Mario avatar
    8 posts

    Posted 28 Jan 2013 Link to this post

    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
  3. Chris
    Chris avatar
    4 posts
    Member since:
    Jun 2012

    Posted 29 Jan 2013 Link to this post

    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.
  4. dan
    dan avatar
    28 posts
    Member since:
    Jun 2016

    Posted 01 Sep 2016 in reply to Mario Link to this post

    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

  5. Boyan Boev
    Admin
    Boyan Boev avatar
    1072 posts

    Posted 06 Sep 2016 Link to this post

    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!
  6. Renjila
    Renjila avatar
    10 posts
    Member since:
    Jul 2018

    Posted 06 Aug 2018 Link to this post

    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

     

  7. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    1050 posts

    Posted 08 Aug 2018 Link to this post

    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!
  8. Renjila
    Renjila avatar
    10 posts
    Member since:
    Jul 2018

    Posted 15 Aug 2018 Link to this post

    Thank you for your inputs!

    Regards,

    Renjila

  9. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    1050 posts

    Posted 15 Aug 2018 Link to this post

    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!
  10. Madhusmita
    Madhusmita avatar
    7 posts
    Member since:
    Sep 2015

    Posted 10 Oct 2018 Link to this post

    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?

     

  11. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    1050 posts

    Posted 15 Oct 2018 Link to this post

    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!
Back to Top