You wanted to make sure that the “elements.get(index1)” is clickable before actually clicking it. It’ a good idea. So you used “WebUI.delay(x)”.
But delay(x) with x being a fixed time duration will make your test unnecessarily slow. You had better use WebDriverWait(driver, timeout).until(condition) to check the visibility of the target element, which would pass and continue to the next step as soon as the condition is met.
See try the following example.
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.support.ui.ExpectedConditions
import org.openqa.selenium.support.ui.WebDriverWait
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
def waitForElementToAppearInDOM(WebDriver driver, WebElement element, int timer) {
new WebDriverWait(driver, timer).until(ExpectedConditions.visibilityOf(element));
}
TestObject makeTestObject(String selector) {
TestObject tObj = new TestObject(selector)
tObj.addProperty("css", ConditionType.EQUALS, selector)
return tObj
}
WebUI.openBrowser("https://katalon-demo-cura.herokuapp.com/profile.php#login")
WebUI.verifyElementPresent(makeTestObject("input#txt-username"), 10)
List<WebElement> list = WebUI.findWebElements(makeTestObject("button#btn-login"), 10)
waitForElementToAppearInDOM(DriverFactory.getWebDriver(), list.get(0), 10)
list.get(0).click()
WebUI.closeBrowser()
Please use and modify this example so that it fits to your case.
(I learned this code from java - How to wait for a WebElement to be present within the DOM? - Stack Overflow)