c# - Selenium WebDriver - 如何在表中找到行的索引
问题描述
我想通过 Selenium 在表(10 行)中找到行的索引:
<table _ngcontent-c4="" class="table table-striped table-br" xpath="1">
<tr _ngcontent-c4="" plan-id="41220451" xpath="1">
<tr _ngcontent-c4="" plan-id="41220452" xpath="1">
<tr _ngcontent-c4="" plan-id="41220453" xpath="1">
<tr _ngcontent-c4="" plan-id="41220454" xpath="1">
<tr _ngcontent-c4="" plan-id="41220455" xpath="1">
<tr _ngcontent-c4="" plan-id="41220456" xpath="1">
<tr _ngcontent-c4="" plan-id="41220457" xpath="1">
<tr _ngcontent-c4="" plan-id="41220458" xpath="1">
<tr _ngcontent-c4="" plan-id="41220459" xpath="1">
<tr _ngcontent-c4="" plan-id="41220460" xpath="1">
问题是找到行plan_id ="41220457" (index = 7)
我尝试使用几个定位器,但没有成功。
解决方案
让我们找到所有表格行作为列表
var table = chrome.FindElement(By.TagName("table"));
var tr = table.FindElements(By.TagName("tr"));
推荐阅读
- python - 提取至少包含另一个列表项的列表元素的有效方法
- javascript - 无法停止在 Reactjs 中渲染组件
- jenkins-job-dsl - 如何使用 .groovy 配置文件配置 Jenkins 以在我的多分支管道中设置“构建策略 - > 标签”?
- java - java中实例变量的声明和初始化
- php - 如何在 .html 文件中创建的表上显示来自 mysql 的数据
- java - 如何在没有安全 SSL 的情况下制作 wsimport (JAX WS)
- kubernetes - Kubernetes 清单中 hostPath 中的 POD 特定文件夹
- typo3 - TYPO3 核心中是否有用于在渲染前执行代码的 Hook 或 Signal?
- javascript - :target 上的 CSS 即使在更改 location.hash 后仍保持打开状态
- python - 在 Python3.6 中读取 Sql 文件的 MemoryError