Mein Problem ist, ich habe eine dynamische Tabelle, und ich möchte suchen, ob in der Tabelle angegebene Zeichenfolge vorhanden sind. Wenn es existiert, wird es weitergegeben, andernfalls scheitert es. Mein Code istSuchen Sie einen gegebenen Text in der Tabelle und sollte Pass bestehen, wenn vorhanden
Boolean isPresent = false;
WebElement mytable = driver.findElement(By.xpath("html/body/div[1]/div[1]/form/div/table")); //To locate rows of table.
List <WebElement> rows_table = mytable.findElements(By.tagName("tr")); //To calculate no of rows In table.
int rows_count = rows_table.size(); //Loop will execute for all the rows of the table
for (int row = 0; row < rows_count; row++) {
//To locate columns(cells) of that specific row.
List <WebElement> Columns_row = rows_table.get(row).findElements(By.tagName("td"));
//To calculate no of columns(cells) In that specific row.
int columns_count = Columns_row.size();
//System.out.println("Number of cells In Row " + row + " are " + columns_count);
//Loop will execute till the last cell of that specific row.
for (int column = 0; column < columns_count; column++) {
//To retrieve text from the cells.
celltext = Columns_row.get(column).getText();
System.out.println("Cell Value Of row number " + row + " and column num ber " + column + " Is " + celltext);
if (celltext.equals("dfsahdfakjfhka")) {
System.out.println("passed on: " + celltext);
isPresent=true;
}
else {
System.out.println("failed on: " + celltext);
isPresent=false;
}
}
}
if (isPresent==true) {
Assert.assertFalse(true);
}
else{
Assert.assertFalse(false);
}
Wenn es läuft. Kein Fehler wird angezeigt. Tatsächlich hat meine Tabelle nicht den Wert "" dfsahdfakjfhka ". .Passed und Failed Nachricht zeigt korrekt und auch boolean valu 'isPresent' gibt false zurück. Aber assert funktioniert hier nicht
diesem Abschnitt nach. http://stackoverflow.com/ help/how-to-ask –
Was ist das Problem? – Guy