Collect the List of WebElements

Hi,

Scenario: Collect the list of elements and get the size of elements and perform actions on that.

I had collected a list of elements by using:

List listofelements = WebUI.findWebElements(findTestObject(‘Locator’))
for(int i=0;i<listofelements.size();i++)
{
if(listofelements.size()>0)
{
WebUI.click(findTestObject(‘Locator’))
}
}

Is this correct approach for my scenario please help with this… ???

1 Like

Seems valid to me. Please try it out to see if it works and then post the result back.

I am getting following error when running the code.

Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.findWebElements() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject) values: [TestObject - ‘Object Repository/Homepage/closetabs’]
Possible solutions: findWebElement(com.kms.katalon.core.testobject.TestObject), findWebElements(com.kms.katalon.core.testobject.TestObject, int), findWebElement(com.kms.katalon.core.testobject.TestObject, int)

1 Like

You miss some parameter in findWebElements method - TestObject and integer is expected (timeout?)

Now i used the following i am getting different error

List listofelements = WebUiBuiltInKeywords.findWebElements(findTestObject(‘Locator’),30)

Reason:

groovy.lang.MissingPropertyException: No such property: WebUiBuiltInKeywords for class: Script1568722606904
at caseCreation_UpdateCase.run(caseCreation_UpdateCase:33)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1568796438785.run(TempTestCase1568796438785.groovy:21)

Most probably missing import (don’t you use WebUI alias?)

I edited it and kept as WebUI instead of WebUiBuiltInKeywords… i am getting missing method exception. What is meant by missing method exception???

1 Like

Share the logs, and script with the imports

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import org.openqa.selenium.WebElement as WebElement
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable

WebUI.openBrowser(‘https://xyz.com’)

WebUI.maximizeWindow()

WebUI.sendKeys(findTestObject(‘Login/username’), ‘xyz’)

WebUI.sendKeys(findTestObject(‘Login/password’), ‘xyz’)

WebUI.click(findTestObject(‘Login/loginbtn’))

WebUI.delay(35)

WebUI.waitForElementPresent(findTestObject(‘Homepage/elementpresent’), 10)

//WebDriver driver = DriverFactory.getWebDriver()

List pending = WebUI.findWebElements(findTestObject(‘Object Repository/Homepage/closetabs’),30)

for (int i = 0; i < pending.size(); i++) {
if (pending.size() > 0) {
WebUI.click(findTestObject(pending))
}
}



Console Report:

groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.testobject.ObjectRepository.findTestObject() is applicable for argument types: (java.util.ArrayList) values: [[[[CChromeDriver: chrome on XP (345d6d71ff5f726a1af2544d70761961)] -> xpath: //*[@data-key=‘close’]], …]]
Possible solutions: findTestObject(java.lang.String), findTestObject(java.lang.String, java.util.Map)
at caseCreation_UpdateCase.run(caseCreation_UpdateCase:37)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1568796767592.run(TempTestCase1568796767592.groovy:21)

You try to find a List of elements :

But I can’t understand what you’re trying to do. Your List pending is a List of WebElements, so you can’t use the WebUI.click method, because it works with TestObject

Actually after login into application there will be some tabs opened some times or there will be no tabs in that application. so i’m getting close buttons of that tabs in the list and putting in for loop all buttons and if buttons size >0 then we must click on that close tab button.

So, this is the scenario…

Try

for(int i = 0; i < pending.size(); i++) {
    if(pending.get(i).size() > 0) {
        pending.get(i).click()
    }
}
1 Like

Sure, I will try give me 1 min.

yeah, thanks for the logic i changed some of that and tried it worked for me.

List pending = WebUI.findWebElements(findTestObject(‘Object Repository/Homepage/closetabs’), 30)

int closetabsSize = pending.size()

if (closetabsSize > 0) {
for (int i = 0; i < closetabsSize; i++) {
pending.get(i).click()
}
}

1 Like

So, I am getting some errors in mobile testing at the starting stage could be able to help with that?

Please, open a new topic on the Mobile category (with your scenario, the script, and the error log). There the mobile specialists can help you

Sure thank you…

Hi All

I am facing the same issue and was unable to resolve it. Can anyone help me?

This is the error I am facing:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.sendKeys() is applicable for argument types: (org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringWebElement, java.lang.String) values: [[[ExistingRemoteWebDriver: on ANY (6e75c30c06b5f5965053381924cce209)] → xpath: //div[@id=‘QuickResponseGrid’]/div[3]/table/tbody/tr/td[16]], …]
Possible solutions: sendKeys(com.kms.katalon.core.testobject.TestObject, java.lang.String), sendKeys(com.kms.katalon.core.testobject.TestObject, java.lang.String, com.kms.katalon.core.model.FailureHandling)
at Quote Creation LTL-MB.run(Quote Creation LTL-MB:149)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.RawTestScriptExecutor.runScript(RawTestScriptExecutor.java:34)
at com.kms.katalon.core.main.RawTestScriptExecutor.doExecute(RawTestScriptExecutor.java:29)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:415)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:407)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:284)
at com.kms.katalon.core.main.TestCaseMain.runTestCaseRawScript(TestCaseMain.java:179)
at com.kms.katalon.core.main.TestCaseMain$runTestCaseRawScript$0.call(Unknown Source)
at TempTestCase1662639900055.run(TempTestCase1662639900055.groovy:307)

can you show us the code?

The fix to the problem is right in the message. The OP just didn’t have the correct parameters.