This is a migrated thread and some comments may be shown as answers.

Wait for one or the other element

3 Answers 74 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kris
Top achievements
Rank 1
Kris asked on 24 Jul 2012, 07:41 AM
To wait for an element to exist, you have to do this:

var element = app.FindName("element");
element.Wait.ForExists();

In my silverlight application, at some point I have to wait for either elementA to exist or elementB to exist. So I created two tasks that each wait for one of the elements to exist:

var waitForElementATask = Task.Factory.StartNew(() => WaitForElement("elementA"));
var waitForElementBTask = Task.Factory.StartNew(() => WaitForElement("elementB"));
Task.WaitAny(waitForElementATask ,waitForElementBTask);

with WaitForElement() being:

private void WaitForElement(string name)
{
   var element = app.FindName(name);
   element.Wait.ForExists();
}

I thought this would be a good way to find out which one of the two elements show up. However, when I run this code, neither element will ever be found, even though they do show up. 

Anybody has any ideas? 

3 Answers, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 24 Jul 2012, 02:50 PM
Hello Kris,

Please see our code sample article on How to Wait for an Element to Exist in Code.

Also keep in mind that we recommend using code only when absolutely necessary, and you can easily craft a Wait For Exists step from the Elements Menu through the UI without code.

Greetings,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Kris
Top achievements
Rank 1
answered on 25 Jul 2012, 08:52 AM
Hey Anthony, thanks for your reply. I have no problem waiting for a single element. That is already working. However, I don't know how to wait for one of two elements to pop into existence. I guess there is no solution for that in Telerik Test Studio.
0
Anthony
Telerik team
answered on 25 Jul 2012, 05:22 PM
Hello Kris,

I can think of a couple ways to accomplish this:

  • Add an IF/ELSE logical step through the UI. Attach a Wait For Exists verification for element 1 to the IF portion. Add a Wait For Exists verification for element 2 to the ELSE portion.
  • Take a similar approach in code, using either an IF/ELSE or TRY/CATCH statement.


Greetings,
Anthony
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Kris
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Kris
Top achievements
Rank 1
Share this question
or