Data Driven Find Expressions in Coded Step
I need to data drive an element's find expression and use it to perform an action against or verify an element.
Tip! Data driven find expressions is also available directly in elements Edit mode.
The Scenario
The example below uses a page from the Telerik UI for ASP.NET MVC demo site.
- Create a test and navigate to the demo page.
- The ListBox on the left side holds a list of names under the Employees list.
- Select a name and choose the button to move it on the right.
- The selected name is now moved to the right under the Developers list.
- Do consecutive iterations for each of the names in the list on the left.
The Solution
Create a test and record the Navigate step.
-
Prepare the data table - for this example I use the internal data source and it looks like this.
-
Explore the list of items and its structure using the Advanced Recording Tools.
Based on the DOM tree the items from the list are identified as
ListItems
with specificInnerText
property andclass=k-list-item
. These element's attributes are used when defining the find expression for the element in code.Create a coded step in the test.
Start with getting the value from the data source and store into a variable.
Next use the value of that variable to define the string, which needs to be used in the find expression definition.
Form the find expression definition and assert a matching element exists on the page.
-
Click the matching element.
Complete coded step looks like this:
// Get current iteration value from data source var dataIterVal = Data["EmplNames"]; // Define a string which adds the value taken from data source as inner text for the find expression string defForFE = "InnerText="+dataIterVal.ToString(); // Search for the list item element using find expression with the help of the defined string value HtmlListItem nameToSelect = Find.ByExpression<HtmlListItem>("class=k-list-item", defForFE ); Assert.IsNotNull(nameToSelect); // Click the corresponding item from list nameToSelect.MouseClick(ArtOfTest.WebAii.Core.MouseClickType.LeftClick, 0, 0, ArtOfTest.Common.OffsetReference.AbsoluteCenter); ```
10. Switch back to the test steps and record the click on the button to move the selected item on the right. With this the scenario is complete.