[英]How to check that all items in the list contains any character from string
List<WebElement> elements = driver.findElements(By.className("price"));
for (WebElement element : elements) {
System.out.println(element.getText());
}
String currency = driver.findElement(By.cssSelector("#_desktop_currency_selector > div > span.expand-more._gray-darker.hidden-sm-down")).getText();
System.out.println(currency);
我的清單包含: 22,33 $ 44,22 $ 22,11 $...
還有一個字符串,其中包含: USD $
我的測試需要檢查位於站點 header 的下拉列表中的貨幣類型是否與所有顯示項目中的貨幣類型字符匹配。
如果列表中的所有元素都包含貨幣設置中的任何符號(例如 $) - 測試通過,否則失敗
嘗試使用包含但仍然無法使其工作的斷言...我將不勝感激
首先,我將提取貨幣符號(假設:它是currency
字符串末尾的單個字符):
String currencySymbol = currency.substring(currency.length() - 2);
然后,我將 go 覆蓋所有元素並檢查它們是否包含它:
for (WebElement element : elements) {
// You should probably also add a user-friendly message here
assertTrue(element.getText().endsWith(currencySymbol));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.