如何使用 Selenium 在表格中查找特定行? [英] How to find specific lines in a table using Selenium?
问题描述
这是一个示例代码:
<div id="productOrderContainer">
<table class="table gradient myPage">
因此,productOrderContainer 中的这个表有几列,并且根据几项内容将有几行,这些行都有几列.一个例子是:
So this table being in productOrderContainer has several columns and depending on several things will have several rows which all have several columns. An example is:
我想要做的是例如获取该表的第一行.(行具有 id,例如:<td rowspan="1">
)然后再次例如在此行跨度中查找特定 <div>代码>
What I want to do is to for example get the first row of this table. ( rows have id's such as: <td rowspan="1">
) And then again for example in this rowspan look for a specific value in a specific <div>
所以在伪代码中我想说的是:
So in psudo-code what I want to say is:
给我表格,给我第n行,给我<div id='something'>
Get me the table, get me the n'th row, get me the value in <div id='something'>
推荐答案
你可以试试关注
int index = 0;
WebElement baseTable = driver.findElement(By.className("table gradient myPage"));
List<WebElement> tableRows = baseTable.findElements(By.tagName("tr"));
tableRows.get(index).getText();
您还可以遍历 tablerows 以执行您想要的任何功能.
You can also iterate over tablerows to perform any function you want.
这篇关于如何使用 Selenium 在表格中查找特定行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!