Checking a checkbox with Katalon and checking it manually doesn't trigger same event?

Hello,

I noticed something very odd while using the check and uncheck checkbox instruction. The webpage I’m testing is supposed to show more options when a checkbox is “checked”, however Katalon doesn’t seem to trigger this. I can see the checkbox is checked but nothing else happens:

Here’s a screenshot of the panel:
image

Here’s a screenshot of the checked checkbox using Katalon:
image

Here’s a screenshot of how the panel looks like when you check the checkbox manually:
image

Using Katalon’s “click” function does make the other info and menus pop up as they should, but that defeats the purpose and I wanna check and uncheck the checkbox, not click it.

Anyone else has a solution to this problem? Any feedback is much appreciated.

By the way, if this info is useful I’m checking the checkbox using javascript and a keyword and a CSS selector to “find” the checkbox. Like so:

def checkUsingJS(TestObject to3, int timeout3) {
WebDriver driver = DriverFactory.getWebDriver()
WebElement element = WebUiCommonHelper.findWebElement(to3, timeout3)
JavascriptExecutor executor = ((driver) as JavascriptExecutor)
executor.executeScript(‘arguments[0].checked = true’, element)
}

def uncheckUsingJS(TestObject to4, int timeout4) {
WebDriver driver = DriverFactory.getWebDriver()
WebElement element = WebUiCommonHelper.findWebElement(to4, timeout4)
JavascriptExecutor executor = ((driver) as JavascriptExecutor)
executor.executeScript(‘arguments[0].checked = false’, element)
}

image
Thanks!

If Katalon click the checkbox then click something else, does the additionnal options appear ?

I thought about it too but it doesn’t. The additional options only appear using the click option or by checking it manually.

Yeah, me too (but I don’t mess too much with webdriver like that, I let the browser do it).

The issue is this:

  1. The element itself responds to click events (also, keyboard events - it can be selected when it has focus using the spacebar). These can be accessed from code using the click() method.

  2. The element also triggers a change event (onchange’) when it changes state. That is to say, there is no native “checked” event, nor, indeed, an “unchecked” event.

Which all amounts to saying, what you are doing is completely fine, pragmatic even. You are unsatisfied with the basis of the Katalon/Selenium methodology and you devised a better solution. Take a pat on the back and move on :sunglasses:

1 Like

Thanks for the response. So you’re saying there’s no way around this problem? This is a known issue with Katalon then?

Do you know if there’s anything I can do on my end? Maybe the checkbox only responds to click events which is wrong no?

I’m saying that’s how it works.

You could say that, yes. It’s a selenium issue, more than a Katalon one.

Like I said, what you’re doing is fine. I do something very similar.

I answered that.

I understand. Thank you.

@dasu07, please accept my apologies - I misunderstood a nuance of what you were actually asking. Let me try to answer your original question a little better.

Perhaps I missed it, but you didn’t mention WebUI.check() which I assume is the comparison you’re making when talking about using JavaScript to perform the check operation. Again, what you are doing is fine. However, it is not what I do, despite what I said earlier – this is the part of your message I misunderstood.

I use Javascript to click() the element. I do this for the reasons I stated. There is no “check” method. There is only a click() method and a change event. It doesn’t matter what Katalon or Selenium invent to put in their APIs. At the end of the day, click and change is all there is.

Now, your application is doing one of two things:

  1. Listening for clicks on the checkbox and acting according to it’s state.

  2. Listening to onchange events on the checkbox and acting according to it’s state.

Your investigation has proved that Katalon (Selenium) is not providing what your page needs.

Your test code proves that your application page is very likely listening to onchange events (because that is what your JavaScript is doing, triggering a change event).

I hope that helps a little more?

1 Like

Thanks for the feedback. I didnt’ mention WebUI.check() because I’m using Javascript to do the check and uncheck operations. The “webUI.check” was not working for me so I had to use other solution like so:

@keyword
def checkUsingJS(TestObject to3, int timeout3) {
WebDriver driver = DriverFactory.getWebDriver()
WebElement element = WebUiCommonHelper.findWebElement(to3, timeout3)
JavascriptExecutor executor = ((driver) as JavascriptExecutor)
executor.executeScript(‘arguments[0].checked = true’, element)
}

CustomKeywords.‘newpackage.keywordtest.checkUsingJS’(findTestObject(‘Object Repository/Page_Rdgivarstdet/incomeSalary_1’), 30)

Then and only then was I able to check and uncheck the boxes and my leisure but I noticed it wasn’t triggering the change event to show the other info, so yes you are most likely right, the webapp is listening for clicks. I’m checking with the developers if that’s the case.

I suspect I will most likely have to do a happyflow in which I know exactly the state of the checkbox before I enter the page to click on it.

hi,

what will happen if one checkbox is selected and you press the enter key?
WebUI.sendKeys(findTestObject(‘null’), Keys.chord(Keys.ENTER))

Thanks, yes. Simply clicking or sending a TAB or an ENTER to the test object fixes the problem. That’s how the system is purposely built apparently.

hi,
sometimes it’s much easier as you think :smile: