Sto cercando di analizzare le righe in una tabella HTML utilizzando href xpath parziale ed eseguire ulteriori test con gli altri valori di colonna di quella riga.Come ottenere una riga della tabella HTML con Capybara
<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>
In cetriolo-JVM definizione passo, ho eseguito questo molto facilmente come qui di seguito (io sono più a suo agio con Rubino)
@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);
}
}
Sono senza tracce qui
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
}
}
Hi Ko, come faccio ad ottenere il href del collegamento che corrisponde a xpath. Devo controllare alcune cose con i valori della colonna della riga corrispondente. Quindi, come ottengo le colonne corrispondenti (valori)? – Bala
È possibile utilizzare i cercatori normali per ispezionare il tr. Un esempio è stato aggiunto –
Errore di selenio 'Elemento non trovato nella cache - forse la pagina è cambiata da quando è stata cercata ...'. Ma funziona se ho semplicemente messo tr.text' rimuovendo 'tr.has_selector? ...'. – Bala