C# 如何使用WebElement selenium C按名称获取表中列的索引#

C# 如何使用WebElement selenium C按名称获取表中列的索引#,c#,selenium,html-table,C#,Selenium,Html Table,我试图按名称获取列(或行)表的索引,但我正在使用seleniumWebElement捕获表或列、行的接口,。。。。我无法将捕获的表存储到数据表(在System.Data.dll引用中)。我已读入,但无法将表列中的数据存储到DataColumn,并使用DataColumn.Ordinal获取数据。这是我的界面: IWebElement Table = driver.FindElement(By.XPath("//*[@class='DivTable']//table")); ReadOnlyCol

我试图按名称获取列(或行)表的索引,但我正在使用selenium
WebElement
捕获表或列、行的接口,。。。。我无法将捕获的表存储到
数据表
(在System.Data.dll引用中)。我已读入,但无法将表列中的数据存储到
DataColumn
,并使用
DataColumn.Ordinal
获取数据。这是我的界面:

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
    }
}
IWebElement Table=driver.FindElement(By.XPath(“//*[@class='DivTable']///Table”);
ReadOnlyCollection allRows=Table.FindElements(按.TagName(“tr”));
foreach(所有行中的IWebElement行)
{
ReadOnlyCollection allCols=row.FindElements(按.TagName(“td”));
foreach(所有列中的IWebElement列)
{
//做点什么
}
}

我做到了,我想把它分享给像我这样的初学者: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;
}
}
String sColValue=“许可”;
//第一个循环将在第一列中找到“ClOCK TWER HOTEL”

因为(inti=1;i我做到了,我想把它分享给像我这样的初学者: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;
}
}
String sColValue=“许可”;
//第一个循环将在第一列中找到“ClOCK TWER HOTEL”

对于(int i=1;i请添加表格htmlHow i add?您可以为我演示吗?请单击问题下方的“编辑”并将其添加到您的问题中。请添加表格htmlHow i add?您可以为我演示吗?请单击问题下方的“编辑”并将其添加到您的问题中。