如何从.size中删除空间。
java.lang.AssertionError:预期[9]但发现[9]
List<WebElement> editicons =
driver.findElements(By.xpath("//i[@class='material-icons']"));
for (int j = 1; j <= editicons.size(); j++) {
editicons = driver.findElements(By.xpath("//i[@class='material-icons']"));
String porfolioName = driver.findElement(By.xpath("(//mat-table//mat-row)[" + j + "]//mat-cell[2]"))
.getText();
Thread.sleep(1000);
Reporter.log("Successfully rendered no " + porfolioName);
Add_Log.info("Successfully rendered no " + porfolioName);
}
String savecount = driver.findElement(By.xpath("//div[@class='mat-paginator-range-label']")).getText();
String[] trimmedText = savecount.split("of");
Reporter.log("Total number of Approve: " + trimmedText[1]);
Add_Log.info("Total number of Approve: " + trimmedText[1]);
Assert.assertEquals(editicons.size(), trimmedText[1]);
}
答案 0 :(得分:1)
使用Integer类(int数据类型的包装器类)的静态方法String
将Integer
转换为parseInt
。要消除开头和结尾的空格,我们可以使用String
类trim
方法。
Assert.assertEquals(editicons.size(), Integer.parseInt(trimmedText[1].trim));