How to use RegEx in Find Logic?

6 posts, 0 answers
  1. Madhu
    Madhu avatar
    23 posts
    Member since:
    Dec 2010

    Posted 09 May 2011 Link to this post

    Hello Support,

    How to use Regular Expressions (RegEx) in building a Find logic?
    If you could have any tutorial/videos, it will really helpful.

    Thanks,
    Madhu.
  2. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 09 May 2011 Link to this post

    Hello Madhu,

    Check out the detailed step-by-step guide on Test Studio. A simple search on "RegEx" will take you to the chapter on regular expression:
    http://www.telerik.com/documents/automated-testing-tools/WebUITestStudioQAEditionStepByStep.pdf

    Test Studio uses regular expressions the same way they're used in the .NET Framework. What this means is that you can look at any .NET RegEx tutorials. Here is an example I found useful:
    http://support.microsoft.com/kb/308252  

    In this tutorial you can see an example:
    Regex emailregex = new Regex("(?<user>[^@]+)@(?<host>.+)"); 
    which is a regular expression object used to describe an e-mail pattern. For instance:
    johndoe@tempuri.org

    If you wanted to verify an e-mail link using Test Studio you can use the same regular expression in your regex verification: (?<user>[^@]+)@(?<host>.+)

    I hope this answers your question; please don't hesitate to contact us again if you need more help.

    Regards,
    Anthony
    the Telerik team
    Do you think you know all the new features coming out in Test Studio R1 2011? Think again - we have some surprises and will share them with you in the What's New in Test Studio R1 2011 Webinar on May 12th.
    Register Today!
  3. Rohit
    Rohit avatar
    10 posts
    Member since:
    Dec 2011

    Posted 19 Jan 2012 Link to this post

    How to find an element using expression.

    My Scenario is :-
    In My application there is link generated at Run time. It is a hyperlink which contain(IA:Auto1234567890 | rohit malhotra | 4000 rs)
    I want to find this hyperlink with only this string "Auto1234567890" instead of  (IA:Auto1234567890 | rohit malhotra | 4000 rs) exact same. 

    i used the code snippet below:-

    Manger.ActiveBrowser.Imagehyperlink.Find.ByTextContent("Auto1234567890").Highlight();
    Manger.ActiveBrowser.Imagehyperlink.Find.ByTextContent("~Auto1234567890").Highlight(); (contains)
    Manger.ActiveBrowser.Imagehyperlink.Find.ByTextContent("%{Auto1234567890}%").Highlight(); (using wild cards)

    All are fails Element not found :( :( :( :( :( 


    but it fail  :( :( :( :( :(  


    Please help me how can i find the element which contains string only "Auto1234567890" instead of  (IA:Auto1234567890 | rohit malhotra | 4000 rs) exact same.



     
  4. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 19 Jan 2012 Link to this post

    Hello Rohit,

    Use the following code to locate a link based on a partial match of its text content:

    HtmlAnchor a = Find.ByExpression<HtmlAnchor>("textcontent=~Auto1234567890");
    Assert.IsNotNull(a);
    a.Click();

    Find more information here.

    Kind regards,
    Anthony
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Rohit
    Rohit avatar
    10 posts
    Member since:
    Dec 2011

    Posted 20 Jan 2012 Link to this post

    Hi Anthony,

    we are using silverlight application please tell me solution regarding the same.
  6. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 20 Jan 2012 Link to this post

    Hello,

    Use the following code to locate a Silverlight element based on a partial match of its text content: 

    SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
    FrameworkElement fe = app.Find.ByTextContent("~Auto1234567890");
    fe.User.Click();

    See here for more information. 

    Regards,
    Anthony
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top