如何找到在使用Selenium表中特定行? [英] How to find specific lines in a table using Selenium?
问题描述
下面是一个例子code:
Here is an example code:
<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:
我想要做的是例如获得此表的第一行。 (行有编号的,如:&LT; TD ROWSPAN =1&GT;
)在一个特定的这行跨度查找特定的值,然后再例如&LT; DIV&GT;
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>
因此,在psudo- code什么,我想说的是:
So in psudo-code what I want to say is:
给我桌子上,让我第n行,让我的价值&LT; DIV ID ='东西'&GT;
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屋!