I'm using Selenium Webdriver to iterate the rows of a table and creating an instance of class T for each row, setting properties on the object based on data in the row:
public override void RefreshElements()
{
base.RefreshElements();
var browseTableRows = Driver.FindElements(By.CssSelector("table.browse>tbody>tr"));
ItemsList = new List<T>(browseTableRows.Count);
ItemsById = new Dictionary<int, T>(browseTableRows.Count);
foreach (var tr in browseTableRows) {
T item = new T() {
ID = int.Parse(tr.FindElement(By.XPath("td[2]")).Text),
Name = tr.FindElement(By.XPath("td[3]")).Text,
Description = tr.FindElement(By.XPath("td[4]")).Text
};
ItemsList.Add(item);
ItemsById.Add(item.ID, item);
}
}
This code is quite slow. Any suggestions on how I can speed up this code?
Just to be clear, class T doesn't do anything elaborate:
public class T
{
public int ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
In case it's useful, I'm using version 2.29.1 of Selenium, .NET 4.0 and I'm running the Internet Explorer driver.