Using regular expression in Elements/Find Element

5 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
    27 posts
    Member since:
    Jun 2016

    Posted 01 Sep 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
    1040 posts

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