1

I tried to get the index of column (or row) table by name but I'm using selenium WebElement to capture interface of table or column, row,.... and I can't store captured table to DataTable (in System.Data.dll reference). I read in get index of DataTable column with name but I cannot store data in column of table to DataColumn and get it by using DataColumn.Ordinal. Here is my interface:

IWebElement Table = driver.FindElement(By.XPath("//*[@class='DivTable']//table"));
ReadOnlyCollection<IWebElement> allRows = Table.FindElements(By.TagName("tr"));
foreach(IWebElement row in allRows)
{
    ReadOnlyCollection<IWebElement> allCols = row.FindElements(By.TagName("td"));
    foreach (IWebElement col in allCols)
    {
       //do something
    }
}
Community
  • 1
  • 1
Tran Manh
  • 71
  • 1
  • 6

1 Answers1

0

I did it, and I would like to share it to everyone who is beginner like me :D

String sColValue = "Licensing";


//First loop will find the 'ClOCK TWER HOTEL' in the first column
for (int i=1;i<=allCols.Count;i++){
    string sValue = null;
    sValue = driver.FindElement(By.XPath(".//*[@id='post-2924']/div/table/tbody/tr[1]/th["+i+"]")).Text;
    if(sValue.Equals(sColValue)){

        // If the sValue match with the description, it will initiate one more inner loop for all the columns of 'i' row 
        for (int j=1;j<=2;j++){
            string sRowValue= driver.FindElement(By.XPath(".//*[@id='post-2924']/div/table/tbody/tr["+j+"]/td["+i+"]")).Text;
            Console.WriteLine(sRowValue);
        }
    break;
}
}

You see, the index of column is "i" :D

Tran Manh
  • 71
  • 1
  • 6