Find a value in a Table.
Posted: Thu Jul 12, 2012 9:56 pm
We have a tables with embebed buttons and I need to be able to match a value in a table and select its button.
The find value part.
In use clicking the button.
Hope you find it helpfull.
The find value part.
Code: Select all
/// <summary>
/// Searches a table for a particular text value, and then finds a corresponding UI element in that row.
/// </summary>
/// <param name="table">Table to search.</param>
/// <param name="rowText">Text to find in a row. e.g. "Bob Smith"</param>
/// <param name="rowTextExpression">XPath Expression used to find the text. e.g. "./span"</param>
/// <param name="adapterExpression">Expression used to return the adapter, once the text has been found. e.g. "../div/input[@type='text']"</param>
/// <returns></returns>
public static T SearchTable<T>(Adapter table, string rowText, string rowTextExpression, string adapterExpression) where T : Adapter
{
// Find Licence and push select
foreach (TrTag row in table.Find("./tbody/tr"))
{
foreach (TdTag cell in row.Find("./td"))
{
WebElement span = cell.FindSingle(rowTextExpression);
if (span.InnerText == rowText)
{
T element = row.FindSingle<T>(adapterExpression);
return element;
}
break;
}
}
return null;
}
Code: Select all
public void FindButton(string argument1)
{
var button = UserCodeModule1.SearchTable<InputTag>(repo.Select_Licensee1.LicenceeTable, argument1, "./span", "./td/input");
if (button != null)
{
button.Click();
Report.Success("Licencee Found", argument1);
}
}