首页 > 解决方案 > 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)

我尝试使用几个定位器,但没有成功。

标签: c#htmlselenium

解决方案


让我们找到所有表格行作为列表

var table = chrome.FindElement(By.TagName("table"));
var tr = table.FindElements(By.TagName("tr"));

推荐阅读