WaitUntilReady() is not working as expected

2 posts, 0 answers
  1. Theja
    Theja avatar
    2 posts
    Member since:
    Apr 2013

    Posted 19 Apr 2013 Link to this post

    I am using Telerik.Testing.Framework.2012.2.1527
    I am using the below code. I am getting null for "findElem" all the time. but when I am in debug mode it is fine. WaitUntilReady(); is not working as expected for me. In my scenario I should not be using waitforelement and specify timeout.

    public bool IsPresentbyInputId(string findCondition)
        Element findElem = Manager.ActiveBrowser.Find.ByExpression(new HtmlFindExpression("tagname=input", "id=" + findCondition));
        return findElem != null && !findElem.Attributes.Any(s => s.Value.Contains("display:none"));

    If I set the Execution Delay to >500, my tests are running fine. But if I give it 0 they fail to find elements.
    Manager.Settings.ExecutionDelay = 500;
    Can you let m know what I am missing here?
  2. Cody
    Cody avatar
    3354 posts

    Posted 24 Apr 2013 Link to this post

    Hello Theja,

    I apologize for the delay getting back to you on this.

    One thing to keep in mind is that WaitUntilReady is monitoring the browsers "Ready" flag. This flag is set as soon as the browser is done the main HTML page (e.g. MyPage.html) plus any referenced resources (images, css files, js files, etc.). It does not take into account any Ajax Postbacks that are initiated as a result of the JavaScript getting control once the page is loaded.

    Ajax Postbacks (usually shown visually via a some type of spinning circle as data is being fetched from the web server) can cause the DOM to be modified long after WaitUntilReady returns control to your test code. If setting Execution Delay > 500 makes your test work, it's my bet your application is doing Ajax Postbacks causing the DOM to change.

    There are two possible ways to overcome this particular problem:
    1) Add a ActiveBrowser.WaitForAjax() call right after the WaitUntilReady() call. This will cause your test to wait until all Ajax connections to your web server are closed.
    2) Add a WaitForElement after the WaitUntilReady. For example:
    ActiveBrowser.WaitForElement(new HtmlFindExpression("id=maindiv"), 30000, false);
    This will cause your code to wait for an element matching the specified properties to exist before moving on.

    I hope this helps.

    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top