Element Present but Not Visible

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.

I can link more information if needed.

Why not replace your verifyElementPresent() check with verifyElementVisible()?:

if(verifyElementVisible(testObject, failure)) {
    // Do something...
}

Note: You don’t need to do == true check, as it’s redundant.

If that doesn’t meet your requirements, I can suggest another way using Selenium directly.

In trying that, i get this error:

2019-01-31 14:52:15.212 e[1;31mERRORe[0;39m e[36mc.k.katalon.core.main.TestCaseExecutor -e[0;39m e[31m❌ for (def index : (1…data.getRowNumbers())) FAILED.e[0;39m
e[31mReason:e[0;39m
e[31mgroovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementVisible() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject, java.lang.Integer, com.kms.katalon.core.model.FailureHandling) values: [TestObject - ‘Object Repository/Staging/Page_DynamicWipDoc - eRecording/input__ConsiderationAmount’, …]e[0;39m
e[31mPossible solutions: verifyElementVisible(com.kms.katalon.core.testobject.TestObject, com.kms.katalon.core.model.FailureHandling), verifyElementVisible(com.kms.katalon.core.testobject.TestObject), verifyElementNotVisible(com.kms.katalon.core.testobject.TestObject, com.kms.katalon.core.model.FailureHandling), verifyElementNotVisible(com.kms.katalon.core.testobject.TestObject)

I assumed the == true was redundant, one of the scripts i was looking at had it, so figured i’d try to see if it changed things.

Edit: this specific error might have been b/c i left the timeout int in.

It is, and that’s actually not your fault for assuming that it should take a timeout arg. See this topic for why:

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?

So, by having the failure argument in the If argument, it will still run the content on failure?

I removed the failure argument from it and it throws a visibility error again.

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…

1 Like

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.

Should I assume that it’s working as you expect now? Or anything else I can clarify?

No, it’s throwing this error currently; doesnt seem to want to ignore the fact that the element is not visible.

e[31mcom.kms.katalon.core.exception.StepFailedException: Unable to verify object ‘Object Repository/Staging/Page_DynamicWipDoc - eRecording/input__ConsiderationAmount’ is visible (Root cause: com.kms.katalon.core.exception.StepFailedException: Object ‘Object Repository/Staging/Page_DynamicWipDoc - eRecording/input__ConsiderationAmount’ is NOT visible)

Hmmm ok, can you share your exact test code with me?

I attached a copy of the script, it runs from another script that calls it up. It runs everything so far up to the ‘Consideration Amount’ section

Script1544133411100.zip (2.8 KB)

Perfect, thanks.

So this is the piece we care about:

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):

println(WebUI.verifyElementVisible(findTestObject('Object Repository/Staging/Page_DynamicWipDoc - eRecording/input__ConsiderationAmount')))

So you will need to add a FailureHandling arg to this if you want to even get to the if statement:

println(WebUI.verifyElementVisible(findTestObject('Object Repository/Staging/Page_DynamicWipDoc - eRecording/input__ConsiderationAmount'), FailureHandling.CONTINUE_ON_FAILURE))

2.) You want to execute the code within the if statement, only if the element is visible. So instead of:

if(WebUI.verifyElementVisible(findTestObject('Object Repository/Staging/Page_DynamicWipDoc - eRecording/input__ConsiderationAmount'))){
    // Do something...
}

Try:

if(WebUI.verifyElementVisible(findTestObject('Object Repository/Staging/Page_DynamicWipDoc - eRecording/input__ConsiderationAmount'), FailureHandling.CONTINUE_ON_FAILURE)){
    // Do something...
}
1 Like

Println is for debug yes.

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

Perfect, so your issue is resolved!

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.

2019-01-31 17:04:59.149 e[39mDEBUGe[0;39m e[36m.03 eCourier - Create New WiP Package(s) -e[0;39m e[39m16: println(verifyElementPresent(findTestObject(“Object Repository/Staging/Page_DynamicWipDoc - eRecording/input__ConsiderationAmount”), 5, STOP_ON_FAILURE))e[0;39m
true
2019-01-31 17:04:59.309 e[39mDEBUGe[0;39m e[36m.03 eCourier - Create New WiP Package(s) -e[0;39m e[39m17: println(verifyElementVisible(findTestObject(“Object Repository/Staging/Page_DynamicWipDoc - eRecording/input__ConsiderationAmount”), CONTINUE_ON_FAILURE))e[0;39m
2019-01-31 17:05:00.236 e[1;31mERRORe[0;39m e[36mc.k.k.core.keyword.internal.KeywordMain -e[0;39m e[31m❌ Object ‘Object Repository/Staging/Page_DynamicWipDoc - eRecording/input__ConsiderationAmount’ is NOT visiblee[0;39m
false
2019-01-31 17:05:00.237 e[39mDEBUGe[0;39m e[36m.03 eCourier - Create New WiP Package(s) -e[0;39m e[39m18: if (verifyElementPresent(findTestObject(“Object Repository/Staging/Page_DynamicWipDoc - eRecording/input__ConsiderationAmount”), 2) && verifyElementVisible(findTestObject(“Object Repository/Staging/Page_DynamicWipDoc - eRecording/input__ConsiderationAmount”), STOP_ON_FAILURE))e[0;39m
2019-01-31 17:05:00.860 e[1;31mERRORe[0;39m e[36mc.k.k.core.keyword.internal.KeywordMain -e[0;39m e[31m❌ Object ‘Object Repository/Staging/Page_DynamicWipDoc - eRecording/input__ConsiderationAmount’ is NOT visiblee[0;39m
2019-01-31 17:05:01.412 e[1;31mERRORe[0;39m e[36mc.k.k.core.keyword.internal.KeywordMain -e[0;39m e[31m❌ Unable to verify object ‘Object Repository/Staging/Page_DynamicWipDoc - eRecording/input__ConsiderationAmount’ is visible (Root cause: com.kms.katalon.core.exception.StepFailedException: Object ‘Object Repository/Staging/Page_DynamicWipDoc - eRecording/input__ConsiderationAmount’ is NOT visible)e[0;39m
2019-01-31 17:05:01.420 e[1;31mERRORe[0;39m e[36mc.k.katalon.core.main.TestCaseExecutor -e[0;39m e[31m❌ for (def index : (1…data.getRowNumbers())) FAILED.e[0;39m
e[31mReason:e[0;39m
e[31mcom.kms.katalon.core.exception.StepFailedException: Object ‘Object Repository/Staging/Page_DynamicWipDoc - eRecording/input__ConsiderationAmount’ is NOT visible

@Brandon_Hein regardless if I can get this figured out properly, you’re help with this
issue is extremely appreciated.

Not really, but I get what you mean.

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.