Моя проблема в том, что у меня есть динамическая таблица, и я хочу выполнить поиск, если данная строка существует в таблице. Если он существует, он передается, в противном случае терпит неудачу. Мой код:Указать заданный текст в таблице и показать пропуск, если существует
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);
}
Когда он бежит. Ошибка не отображается. Фактически у моей таблицы нет значения «dfsahdfakjfhka». Сообщение с сообщением «Пассирование и неудача» отображается правильно, а также «boolean valeu» isPresent возвращает false. Но утверждение здесь не работает.
Обратитесь в этот раздел. http://stackoverflow.com/ help/how-to-ask –
В чем проблема? – Guy