WebUI.verifyElementVisible(TestObject o) and WebUI.verifyElementPresent(TestObject o) not working

WebUI.verifyElementVisible(TestObject o) and WebUI.verifyElementPresent(TestObject o) should return false when element is not visible nor present but instead it just stop the whole process with the not found message.

For example:
if (WebUI.verifyElementVisible(findTestObject(‘button_Add’))) {
WebUI.click(findTestObject(‘button_Add’))
}

The condition is not true so false should be returned which means clicking should be skipped but instead it dies once it hits the conditional statement (the if statement). Same thing happens when use the verifyElementPresent() method.

2 Likes

According to the document https://docs.katalon.com/display/KD/[WebUI]+Verify+Element+Visible , WebUI.verifyElementVisible() requires 2nd argument as int “timeout”

your code should rather be for example:

WebUI.verifyElementVisible(findTestObject('button_Add'),    10, FailureHandling.STOP_ON_FAILURE)
WebUI.click(findTestObject('button_Add'))
2 Likes

There are two verifyElementVisible methods. I used the one with one argument. There’s another one with two arguments. The one you showed me has three arguments.

1 Like

I tried the second method but same thing happened. Here’s the output.
Test Cases FAILED because (of) Unable to verify object ‘Object Repository/button_Add’ is visible (Root cause: Web element with id: ‘Object Repository/Repository/button_Add’ located by ‘By.xpath: //button[@type = ‘button’ and @name = ‘ctl00$cphBody$radBillHistory$ctl00$ctl06$ctl00’ and @id = ‘ctl00_cphBody_radBillHistory_ctl00_ctl06_ctl00’ and (text() = ‘Add’ or . = ‘Add’)]’ not found)

What’s funny is that this method should return a boolean but instead it just kill the process and stop the test all together.

I also have a feeling that the document is not up to date. The two verifyElementVisibles are as follow:
WebUI.verifyElementVisible(TestObject o)
WebUI.verifyElementVisible(TestObject o, FailureHandling flowControl)

Your xpath is

//button[@type = 'button' and @name = 'ctl00$cphBody$radBillHistory$ctl00$ctl06$ctl00' and @id = 'ctl00_cphBody_radBillHistory_ctl00_ctl06_ctl00' and (text() = 'View Statement' or . = 'View Statement')]

Are you sure that this xpath is valid? I can not tell because I can not see the HTML of your target page. I guess the following one would suffice:

//button[text() = 'View Statement']
1 Like

abc said:

I tried the second method but same thing happened. Here’s the output.
Test Cases FAILED because (of) Unable to verify object ‘Object Repository/button_Add’ is visible (Root cause: Web element with id: ‘Object Repository/Repository/button_Add’ located by ‘By.xpath: //button[@type = ‘button’ and @name = ‘ctl00$cphBody$radBillHistory$ctl00$ctl06$ctl00’ and @id = ‘ctl00_cphBody_radBillHistory_ctl00_ctl06_ctl00’ and (text() = ‘Add’ or . = ‘Add’)]’ not found)

What’s funny is that this method should return a boolean but instead it just kill the process and stop the test all together.

Set the FailureHandling.OPTIONAL, otherwise Katalon will mark that step as failed and stop the execution.

1 Like

How can the first loop causes an infinite loop while the second one works fine.

String butts = [‘btn_Add’, ‘btn_Edit’, ‘btn_Cancel’]
for (String b in butts) {
WebUI.click(findTestObject(b))
}

def butts = [‘btn_Add’, ‘btn_Edit’, ‘btn_Cancel’]
for (String b in butts) {
WebUI.click(findTestObject(b))
}

The only diff. is that ‘butts’ is defined as String. When I change String type to def then works fine. What’s going on here.

Try …

String[] butts = [‘btn_Add’ … ]

I think I got it. What I don’t understand is that why it didn’t throw an error when you do String buttons = [‘btn_Add’, ‘btn_Edit’, …]

I was interested. I made a Groovy script.

String butts = ['btn_Add', 'btn_Edit', 'btn_Cancel']
println "butts=${butts}"
for (String b in butts) {
  println "b=${b}"
}

I ran this and got the following result:

$ groovy my.groovy
butts=[btn_Add, btn_Edit, btn_Cancel]
b=[
b=b
b=t
b=n
b=_
b=A
b=d
b=d
b=,
b= 
b=b
b=t
b=n
b=_
b=E
b=d
b=i
b=t
b=,
b= 
b=b
b=t
b=n
b=_
b=C
b=a
b=n
b=c
b=e
b=l
b=]

Well, the code ran as I expected. A finite loop over a string ‘[btn_Add,btn_Edit,btn_Cancel]’

So I guess “,” is now part of the string. It is no longer a separator. I tried to create a list of String and I believe the syntax is String list = [’’, ‘’, ‘’, …]

Is it not?

I tried to create a list of String and I believe the syntax is String list = [’’, ‘’, ‘’, …]

No, your understanding is wrong.

If you want to create a List of String in Groovy, you should write:

List<String> list = ['a','b','c']

If you want to create an array of String in Groovy, you should write:

String[] array = ['a','b','c'] as String[]

On the right-hand side of the statement, you are converting a List to String[].

When you write a statement:

String list = ['a', 'b', 'c']

The right-hand side is a List. But on the left-hand side you are saying you want a String named list. So the Groovy language implicitly convert the List object to a String object. Groovy does not throw an error here as Java does. This difference comes from the language design. So you will get a String variable with value of

[a,b,c]
1 Like