我正在尝试使用部分 href xpath 扫描 HTML 表中的行,并使用该行的其他列值执行进一步测试。
<div id = "blah">
<table>
<tr>
<td><a href="afile?key=HONDA">link</a></td>
<td>29 33 485</td>
<td>45.2934,00 EUR</td>
</tr>
<tr>
<td><a href="afile?key=HONDA">link</a></td>
<td>22 93 485</td>
<td>38.336.934,123 EUR</td>
</tr>
<tr>
<td><a href="afile?key=something_else">link</a></td>
<td>394 27 3844</td>
<td>3.485,2839 EUR</td>
</tr>
</table>
</div>
在 cucumber-jvm 步骤定义中,我很容易执行此操作,如下所示(我更喜欢使用 Ruby)
@Given("^if there are...$")
public void if_there_are...() throws Throwable {
...
...
baseTable = driver.findElement(By.id("blah"));
tblRows = baseTable.findElements(By.tagName("tr"));
for(WebElement row : tblRows) {
if (row.findElements(By.xpath(".//a[contains(@href,'key=HONDA')]")).size() > 0) {
List<WebElement> col = row.findElements(By.tagName("td"));
tblData dummyThing = new tblData();
dummyThing.col1 = col.get(0).getText();
dummyThing.col2 = col.get(1).getText();
dummyThing.col3 = col.get(2).getText();
dummyThing.col4 = col.get(3).getText();
dummyThings.add(dummyThing);
}
}
我在这里一无所知
page.find('#blah').all('tr').each { |row|
# if row matches xpath then grab that complete row
# so that other column values can be verified
# I am clueless from here
row.find('td').each do { |c|
}
page.find('#blah').all('tr').find(:xpath, ".//a[contains(@href,'key=HONDA')]").each { |r|
#we got the row that matches xpath, let us do something
}
}