c# - 如何使用 selenium 和 c# 获取表中的内表数据
问题描述
我想计算外部表的数量。这是我到目前为止所尝试的。在 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>
解决方案
整理出了问题。这里有一些重要的文章>>
1) http://toolsqa.com/selenium-webdriver/c-sharp/handle-dynamic-webtables-with-selenium-in-csharp/
2) http://toolsqa.com/selenium-网络驱动程序/定位器/
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);
谢谢你!!
推荐阅读
- windows - rm -f 命令导致 React.js 出错
- javascript - 块拆分中的自定义模块目录在 Webpack 中不起作用
- google-apps-script - 如何取消其他人在我的电子表格上创建的表单的链接
- ios - 从地图 SWIFT 4.1 中删除选定的 MKAnnotation 时删除错误显示的注释
- python - 使用 openpyxl 查找包含具有特定值的单元格的行
- c++ - 为什么 FlowMonitor 不为 ns3 中的 dsr.cc 收集数据?
- html -
用set引用当前目录 - java - 为什么我不能在 Android 项目上更改用户图像
- django - 如何在 Django Rest 中从不相关的表中添加额外的数据?
- qt - 启动基于 Qt Qml 的应用程序