【问题标题】:How to get Inner Table data in a Table using selenium and c#如何使用 selenium 和 c# 获取表中的内表数据
【发布时间】:2019-02-18 06:22:44
【问题描述】:

我想计算外部表的数量。这是我到目前为止所尝试的。在 HTML 中,我删除了一些部分以减少代码的长度。

var reports =
  driver.FindElements(By.Id("Outer Table"));
var formss = new List < object > ();
foreach(var item in reports) {
  formss.Add(item);
}
<div id="Outer Table" onclick="OnTreeClick(event)">
  <table cellpadding="0" cellspacing="0" style="border-width:0;">
    <tr>
      <td style="white-space:nowrap;">
        <a class="VMIContentPanelHolder_TreeViewSiteSection_0">Fix Auto Leeds (TF 
    Smiths)</a>
      </td>
    </tr>
  </table>
  <table cellpadding="0" cellspacing="0" style="border-width:0;">
    <tr>
      <td style="white-space:nowrap;">
        <a class="VMIContentPanelHolder_TreeViewSiteSection_0">Fix Auto Bradford (TF 
    Smiths)</a>
      </td>
    </tr>
  </table>
</div>

【问题讨论】:

  • 您想要表格内的行数或其他内容?
  • “外表”只是一个 div。您是否要计算 div 中的元素?还是div中表格的行数?需要更清楚。
  • 只有一张桌子不是更好吗?这也可以实现列对齐。
  • 我正在尝试计算#rows
  • 行内数据将添加到另一个表格中ex:-
    修复 Auto Bradford (TF Smiths)

标签: c# html selenium


【解决方案1】:

解决了问题。 这里有一些重要的文章>>
1) http://toolsqa.com/selenium-webdriver/c-sharp/handle-dynamic-webtables-with-selenium-in-csharp/
2)http://toolsqa.com/selenium-webdriver/locators/

IWebElement TableDiv = driver.FindElement(By.CssSelector("#VMIContentPanelHolder_TreeViewSiteSection"));
List<IWebElement> TableTagList = new List<IWebElement>(TableDiv.FindElements(By.TagName("table")));
var reportNameList = new List<string>();
foreach (var TableTag in TableTagList)
 {
  reportNameList.Add(TableTag.FindElement(By.TagName("a")).Text.ToString());
  }
properties.reportCount= reportNameList.Count();
var isListsDiffer = properties.reportList.Except(reportNameList).ToList();
properties.isReportsMatched = !isListsDiffer.Any();
properties.displayValues(properties);

谢谢!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-03
    • 1970-01-01
    • 2020-12-16
    • 1970-01-01
    • 1970-01-01
    • 2017-08-24
    • 2019-06-29
    相关资源
    最近更新 更多