For my test case, I’m creating a loop that builds out packages. Some of the fields that are required for these packages are dependent on the package’s document type selected and are not always visible.
I am trying to create an if statement that verifies the presence of some of these fields using
if(verifyElementPresent(testObject), timeout, failure)==true){
action
}
so far, that line seems to sort of work, it will read that the element is present on the page, although it is not visible, so its running the statement when it shouldn’t and I’m not sure where to go to validate the present but not visible part properly.
I have a continue on failure statement which will run when the if statement fails because it’s not locating the element when its not visible.
After fixing the timeout int, the new error seems to go back to the issue with the element not being visible, but present?
e[31mcom.kms.katalon.core.exception.StepFailedException: Object ‘Object Repository/Staging/Page_DynamicWipDoc - eRecording/input__ConsiderationAmount’ is NOT visiblee[0;39m
e[31m at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:32)
Right, but with your failure handling argument (FailureHandling.CONTINUE_ON_FAILURE), the StepFailedException should be ignored, and your if statement should get evaluated. I’m assuming that’s the behavior you are expecting?
Right, the idea is that the verifyElement____() family of methods act as assertions, which means that, unless you state otherwise, the moment that the assertion returns a value of false, the test will stop.
Providing a FailureHandling.CONTINUE_ON_FAILURE is a way to say: “I’m expecting that this assertion might fail, so go ahead and continue running this script and I will deal with the result myself”. If that makes any sense…
That’s what my thought was in using verifyElement… to validate the elements being there. It’s a slightly confusing error since it says cannot verify the element is visible b/c the element is not visible which was the point?
That does make sense, my assumption was that it would continue past the IF statement, but clearly not the case here.
I’m going to assume that this is what you are trying to accomplish:
1.) The println statement is there for Debug purposes? But remember, if you don’t provide a FailureHandling argument here as well, the test will stop at this line if the element isn’t visible (the assertion fails):
Adding the failures for that section and the one following will push through those sections of script when the fields are not present, although seems to be causing an issue locating the save button in the next lines.
The recent attempt ran through and the consideration field was not visible and those sections failed and the script continued to the pin section where the field was visible although it read it as not visible and failed the println check and the if statement for that section
As an aside, I’ve noticed that you’ve been using the words “present” and “visible” interchangeably. Just as an FYI, there is a distinct difference between an element being present and an element being visible:
1.) An element is considered “present” if it can be found in the DOM, regardeless of its state.
2.) An element is considered “visible” if the element is both present and the element (and all of its ancestor elements) do not have the following attribute: style="display: none;"
I understand the difference between present and visible; code vs ui essentially;
The problem is the same still, the script is not reading the elements properly or I’m not understanding how to properly validate the fields for this situation.
I added a println before the consideration to check both present and visible and present returned true and visible returned false.
So, from my understanding of how visible works; in the IF statement using the visible check, it shouldn’t even run the statement because visible returned false, but it still running and failing at that step even though it will continue through it.
So, I tried checking if the element was present and visible and it errored out saying the element is not visible.
We need to be careful with wording here. The if statement itself will absolutely run. This is because you’ve provided the verifyElementVisible() method with a FailureHandling.CONTINUE_ON_FAILURE argument. Therefore the script will continue to run, and the method will return either true or false. Therefore, the if statement will pick up this boolean value and evaluate it. If the verifyElementVisible() method returns true, the code within the block will be executed, and if it returns false, the code within the block will not be executed.
I don’t understand what you mean by this. Is it stopping at that step, or is it continuing through it? It can’t be both.