我正在为我的工作学习 Katalon,但我遇到了一些问题!
这是我正在尝试做的事情:
1 - 捕获与以下 xpath 匹配的所有元素:
“//div[@class=‘price’]/div[@class=‘pricenew’] | //div[@class=‘price’]/div[@class=‘priceold’] | //div[@class=‘price’]/div[@class=‘oneprice’]”
2 - 完成并存储在 ArrayList 变量中后,我想遍历它并对每个项目执行检查以查看它们是否具有正确的符号。为此,我创建了一个关键字
def checkElements(ArrayList<WebElement> list, String currency) {
for (WebElement price : list) {
String priceItem = WebUI.getText(list(price))
if (WebUI.verifyElementText(priceItem, currency)) {
continue
} else {
System.println("This item doesn't have the correct currency symbol")
}
}
}
事情是:我试过使用 findElements ,我试过使用 findTestObject ,但它们都不起作用(它没有获取元素并存储在数组中)
我的代码现在如下所示:
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
WebUI.openBrowser(‘https://automationteststore.com/’)
WebUI.maximizeWindow()
WebDriver driver = DriverFactory.getWebDriver()
List listPrices = driver.findElements(By.xpath(“//div[@class=‘price’]/div[@class=‘pricenew’] | //div[@class=‘price’]/div[@class=‘priceold’] | //div[@class=‘price’]/div[@class=‘oneprice’]”))
CustomKeywords.‘checkElement.checkElements’(listPrices, ‘$’)
WebUI.enhancedClick(findTestObject(‘Home_Page_Elements/dropdownToggle’))
WebUI.enhancedClick(findTestObject(‘Home_Page_Elements/dropdownPound’))
CustomKeywords.‘checkElement.checkElements’(listPrices, ‘£’)
WebUI.enhancedClick(findTestObject(‘Home_Page_Elements/dropdownEuro’))
CustomKeywords.‘checkElement.checkElements’(listPrices, ‘€’)
WebUI.enhancedClick(findTestObject(‘Home_Page_Elements/dropdownDollar’))
CustomKeywords.‘checkElement.checkElements’(listPrices, ‘$’)
我不断收到的错误是:
Caused by: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.call() is applicable for argument types: (org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement) values: [[[CChromeDriver: chrome on WINDOWS (28974eee30b54427ffbfcfa46388ac70)] -> xpath: //div[@class='price']/div[@class='pricenew'] | //div[@class='price']/div[@class='priceold'] | //div[@class='price']/div[@class='oneprice']]]
有人能帮帮我吗?谢谢!
捕获给定 xpath 的所有元素,将其存储在 ArrayList 变量中并执行断言。