I'm studying Katalon for my Job and I'm having some problems !
Here is what I’m trying to do :
1 - Catch all the elements that matches the following xpath :
“//div[@class=‘price’]/div[@class=‘pricenew’] | //div[@class=‘price’]/div[@class=‘priceold’] | //div[@class=‘price’]/div[@class=‘oneprice’]”
2 - With that done and stored in an ArrayList variable , I wanna iterate through it and perform a check on each item to see if they have the correct symbol . For that , I have created a Keyword
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")
}
}
}
The thing is : I have tried using findElements , I have tried using findTestObject , but none of them works (It doesnt get the elements and store in an array)
My code look as following right now :
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, ‘$’)
The error I keep getting is :
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']]]
Can anyone help me? Thanks !
Catch all the elements given an xpath, store that in an ArrayList variable and perform assertions .