I have many radio buttons on many pages, each page has a Continue button. I use a for loop to get xpath of them. Therefore, I have a need to click on Continue button if an element is not present. Could you please help by an example.
I tried this solution yesterday but it failed as when it looks for an element that is not on the current page but the next page, Katalon shows an error because it can’t find element to verify if it exists:
Unable to verify object ‘link’ is present (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘link’ located by ‘By.xpath: …’ not found)
My sample script:
for (int i = 1; i<=20;i++){
link = new TestObject(“link”)
link.addProperty(“xpath”, ConditionType.EQUALS,“//div[@class='a”+i+“']”, true)
if(WebUiBuiltInKeywords.verifyElementPresent(link, 10) == true){
WebUiBuiltInKeywords.scrollToElement(link, 3)
WebUiBuiltInKeywords.click(link, FailureHandling.STOP_ON_FAILURE)
WebUiBuiltInKeywords.delay(1)
}
else{
WebUiBuiltInKeywords.callTestCase(TestCaseFactory.findTestCase(‘Test Cases/GoNext’), [:],FailureHandling.STOP_ON_FAILURE)
}
In this case, you can insert a check to check for if an element is not present or not. After the check, you can do preceding action based on the check result.
Example:
if (WebUI.verifyElementNotPresent(findTestObject(‘Page_CuraAppointment/btn_BookAppointment’), 10) == true)
{
WebUI.click(findTestObject(‘Page_CuraAppointment/btn_Continue’))
}