I am trying to get a list of the elements that are checked based on ::after
When the checkbox is not selected, the HTML is like this:
But when the checkbox is selected, the only change that happens in HTML is the addition of ::after inside input tag.
Does someone know how I can verify the element checked in this scenario
CSS does not reflect how the checked
property of the DOM element <input type="checkbox">
is.
You can read the DOM element’s checked
profile by javascript inside browser, and it is the only way.
See the following TestCase as example.
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
WebUI.openBrowser('')
WebUI.navigateToUrl('https://katalon-demo-cura.herokuapp.com/')
WebUI.click(findTestObject('Object Repository/Page_CURA Healthcare Service/a_Make Appointment'))
WebUI.setText(findTestObject('Object Repository/Page_CURA Healthcare Service/input_Username_username'), 'John Doe')
WebUI.setEncryptedText(findTestObject('Object Repository/Page_CURA Healthcare Service/input_Password_password'), 'g3/DOGG74jC3Flrr3yH+3D/yKbOqqUNM')
WebUI.click(findTestObject('Object Repository/Page_CURA Healthcare Service/button_Login'))
WebUI.delay(3);
String selector = "input#chk_hospotal_readmission"
String js = "return document.querySelector(\"${selector}\").checked ;"
assert ! WebUI.executeJavaScript(js, null)
WebUI.click(findTestObject('Object Repository/Page_CURA Healthcare Service/input_Apply for hospital readmission_hospit_63901f'))
WebUI.delay(3);
assert WebUI.executeJavaScript(js, null)
WebUI.closeBrowser()
Have you have tried the below statements?
WebUI.verifyElementNotChecked(findTestObject('yourTO'), 10)
or
WebUI.verifyElementChecked(findTestObject('yourTO'), 10)
@grylion54
Since I have the list of checkboxes, what I want to do is to uncheck all the boxes that are checked so I came up with this:
def static removeAppliedCashReward() {
final List<TestObject> cashRewards =
CommonUtils.findVisibleElementsFromTestObject(findTestObject('AccountManagement/AvailableRewardsCheckbox'));
for (int i = 0; i < cashRewards.size(); i++) {
if (WebUI.verifyElementChecked(cashRewards.get(i), 1)) {
WebUI.click(cashRewards.get(i))
}
}
}
But when I call this method, it gives the error:
Caused by: com.kms.katalon.core.exception.StepFailedException: Object '' is not checked
I think when it checks the first checkbox and if it is not checked, it fails the test there. What I want is that if the box is not checked it should continue to the next checkbox
How about adding the FailureHandling option to your condition? I have seen that it seems to be important when we want the full capability of the boolean verification.
if (WebUI.verifyElementChecked(cashRewards.get(i), 1, FailureHandling.OPTIONAL)) {
I was just able to uncheck all the checked boxes with the same code I was using, I just had to add FailureHandling.OPTIONAL
in VerifyElementChecked