我正在对网页进行硒测试,该网页返回一个表格,其中某些行和列显示付款数据。我正在尝试从正在使用的XPATH的结果中剥离一些字符/单词,因为在执行断言时我不需要该部分(检查表中的数据是否正确)。
通常,网页还会在标识号(例如,如下所示的168.3285.6021)之前以文本形式(带有图标)返回“下拉按钮”。 我用的是it.set(it.next()。replaceAll(“ DropDown Arrow”,“”)));因此DropDown Arrow文本将被替换为空,仅适用于第一行,而其他两行则不会被替换。有提示吗?
public void check_receivals() {
// Check how many lines and assert the size (from xpath)
List<WebElement> Receivals = driver.findElements(By.xpath("//*[@id='received-overview']//div[@class='bdpo-overview-table-row']/div[@class='claims']"));
System.out.println(Receivals.size() + " receival lines found");
assertEquals(7, Receivals.size());
// Test data to compare against..aka expectedResultList
List<String> expectedResultList = new ArrayList<>();
expectedResultList.add ("168.3285.6021\n" + "Payment 2015\n" + "01-01-2015\n" + "€ 246");
expectedResultList.add ("143.8407.8413\n" + "Payment 2015\n" + "01-01-2015\n" + "€ 233");
expectedResultList.add ("154.2841.2407\n" + "Payment 2015\n" + "01-01-2015\n" + "€ 253");
// Assert
List<WebElement> ReceivalLines = driver.findElements(By.xpath("//*[@id='received-overview']//div[@class='bdpo-overview-table-row']/div[@class='claims']"));
List<String> ReceivalLines_List = ReceivalLines.stream().map(WebElement::getText).collect(Collectors.toList());
ListIterator<String> it = ReceivalLines_List.listIterator();
while(it.hasNext()) {
it.set(it.next().replaceAll("DropDown Arrow ",""));
assertEquals(ReceivalLines_List, expectedResultList);
答案 0 :(得分:1)
问题是您正在使用迭代器进行修改。我建议使用map函数使替换操作成为流操作的一部分。
List<String> ReceivalLines_List = ReceivalLines.stream().map(WebElement::getText).map(s -> s.replaceAll("DropDown Arrow ","")).collect(Collectors.toList());