How to use wait.for

7 posts, 0 answers
  1. lucia
    lucia avatar
    17 posts
    Member since:
    Jun 2011

    Posted 01 Feb 2012 Link to this post

    Hi,
    Now, I have a scenario like this:

    Some codes will not be executed untill the button is enabled.
    I am wondering how to use wait.for to implement this.

    Thanks!

    lucia
  2. Nitin
    Nitin avatar
    29 posts
    Member since:
    Oct 2010

    Posted 02 Feb 2012 Link to this post

    Hi lucia 

    there is a workaround you can try 

    before performing any Event on button (like click),

    you can use the Code as:-
    button.Wait.ForExists(4000); or button.Wait.ForVisible(4000);

    4000 is time in ms, you can increase its up to you 

    then perform your event 

    Thanks 
    Nitin
  3. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 02 Feb 2012 Link to this post

    Hello Lucia,

    Nitin is correct; those are two good implementations to use. There is also a way to specifically verify if the button is enabled:

    HtmlButton b = Find.ById<HtmlButton>("b1");
    Assert.IsTrue(b.IsEnabled);

    Be aware of the difference between HtmlButton and HtmlInputButton as outlined here.

    The procedure is nearly the same for a Silverlight button:

    SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
    Button b = app.Find.ByAutomationId<Button>("CancelButton");
    Assert.IsTrue(b.IsEnabled);

    @Nitin: I awarded you Telerik points for assisting another customer.

    Kind regards,
    Anthony
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  4. lucia
    lucia avatar
    17 posts
    Member since:
    Jun 2011

    Posted 06 Feb 2012 Link to this post

    Hi Anthony & Nitin
    Thanks for your help!!
    But the workaround you recommended cannot yet resolve my issue because actually the silverlight button always exists and is visible on the page.  Just when the page is loaded, the button is disabled and after waits for a while, the button becomes enabled. So I want to use wait.for to wait some time till the button is enabled and then execute the left codes.
    Any other methods to implement my requirements?
    Thanks a lot!!

  5. Nitin
    Nitin avatar
    29 posts
    Member since:
    Oct 2010

    Posted 06 Feb 2012 Link to this post

    Hi Lucia

    How much time it take to enable (any idea about how many millisecs)
    if yes, then you can use
    System.threading.thread.sleep(int ms);

    or you can check the Button Property if IsEnabled then Click that button using if condition

    if (SilverlightApp.button.isEnabled==true)
    {
    Click on that button
    }

    Hope this Helps
    Thanks


  6. lucia
    lucia avatar
    17 posts
    Member since:
    Jun 2011

    Posted 06 Feb 2012 Link to this post

    HI Nitin
    For now, I just use System.threading.thread.sleep(int ms) to walkaround the issue instead of wait.for . But I still want to know whether I can use wait.for to implement too because if I use the sleep, the time to wait for is a fixed value, and so although the button is enabled before this time, it still waits for the time to execute the next code. Besides, the time to wait is different during every page loading. If I can use wait.for, then the time waitting for the button's being enabled is dynamic, and no need to wait for the fixed value. So I think this will be more efficient. 

    Thanks!!
    Lucia
     

  7. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 06 Feb 2012 Link to this post

    Hello Lucia,

    Use the following code to wait for a Silverlight button to be enabled:

    SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
    Button b = app.Find.ByAutomationId<Button>("CancelButton");
     
    Wait.For<ArtOfTest.WebAii.Silverlight.UI.Button>((a) => ((a.IsEnabled == null) ? (true == null) : a.IsEnabled.Equals(true)), b, false, 15000);


    Greetings,
    Anthony
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top