Lazy wait for HTML elements

4 posts, 0 answers
  1. Harinee
    Harinee avatar
    6 posts
    Member since:
    Mar 2015

    Posted 19 Mar 2015 Link to this post

    Hi,

    I have code like this:

    newElement = Find.ById<HtmlDiv>("someId");  
    //the find is already executed here. But it takes some time before newElement is present on the page. So the find strategy will return null.

    newElement.Wait.ForExists(timeout);              
     //since element was not already present, newElement= null. So wait for exists doesn't really do anything

    Is there a way to have a lazy find strategy? So, only when I wait for the element to exist, does it actually try to find it?
  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1072 posts

    Posted 23 Mar 2015 Link to this post

    Hi Harinee,

    In this case you should for the entire find expression like this:

    HtmlFindExpression expr = new HtmlFindExpression("id=someID");
    ActiveBrowser.WaitForElement(expr, 30000, false);
    Element el = ActiveBrowser.Find.ByExpression(expr);
    ActiveBrowser.Actions.Click(el);

    Let me know if this helps.

    Regards,
    Boyan Boev
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  3. Bharadwaj
    Bharadwaj avatar
    1 posts
    Member since:
    Apr 2018

    Posted 03 May in reply to Boyan Boev Link to this post

    Hi Boyan,

    Thank for your response. By using your above post is there a way we can develop a generic Wait utility using all the Telerik Framework  functions? Please share your thoughts. 

    Regards,

    Bharadwaj.

  4. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    938 posts

    Posted 07 May Link to this post

    Hi Bharadwaj,

    Thanks for reaching us out. 

    You could use the above code shared by Boyan to create that generic wait utility - for example include the code in a method which expects the id to form the find expression as an argument. Then share the method across the project from a utility class.  

    I hope this helps!

    Regards,
    Elena Tsvetkova
    Progress Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
Back to Top