How to get result of Verify Element Visible?

Hi Guys,
I’m using Verify Element Visible to check an element is visible or not. If it is visible then do step 1, or if it is not visible then do step 2.
But I could only get the boolean value as true when the element is visible. If the element is not visible, the testcase will be marked fail with error: Unable to find the element located by ‘By.xpath: abc/def’…
So is there any solution to fix it?

You might want to put in a delay, as the script moves a LOT faster than you or I can see (or if you are moving to a new page, then WebUI.waitForPageLoad(10).

WebUI.waitForElementVisible(findTestObject('yourTO'), 10)
WebUI.verifyElementVisible(findTestObject('yourTO'), 10)

Also, if you are using the verifyElementVisible() in an if condition, add on the FailureHandling.OPTIONAL, like below:

if (WebUI.verifyElementVisible(findTestObject('yourTO'), 10, FailureHandling.OPTIONAL)) {
1 Like

In my case, the element might not be visible to be able to do step 2, so waitForElementVisible and timeout are not possible.

I think you want the last line of @grylion54’s post, the If statement. As long as you include the failure handling as Optional the test case will continue to run if element is visible or not.
If you need a wait then make it a wait for an element that will definitely appear or else just a simple Delay.

It seem something wrong in my script, I fixed and tried again according instructions of @grylion54 and it is working. Many thanks for your help

Just a note that the way you have your code, if the element is visible, both 1 and 2 print out. Is that what you want? If you only want 1 or 2, then make an if else statement, like

if (WebUI.verifyElementVisible(findTestObject('yourTO'), 10, FailureHandling.OPTIONAL)) {
} else {

This way you will only get 1 or 2, not 1 and 2.

1 Like