我想计算外部表的数量。这是我到目前为止尝试过的。在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>
答案 0 :(得分:0)
解决了问题。
这里有一些重要文章>>
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);
谢谢!