5
我想掃描HTML表中的行使用部分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>
在黃瓜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
}
}
柯嗨,我如何才能在href與xpath匹配的鏈接。我需要用匹配行的列值檢查幾件事情。那麼,我如何獲得匹配的列(值)? – Bala
您可以使用正常的發現者來檢查tr。已經添加了一個例子。 –
我得到Selenium錯誤'在緩存中找不到元素 - 可能因爲查找過了頁面而發生了變化...'。但是,如果我簡單地'把tr.text'移除'tr.has_selector? – Bala