Making sure an element is clickable. verifyElementIsClickable not doing it's job

I have solved this problem for certain situations. Not for all.

Before clicking a web element i check if it is clickable. verifyElementIsClickable replies “true” but element is not clickable, script ends with error.

I have a number of elements (products) to choose from for a certain test scenario

xpaths are for example for a given situation (there are more, typically 12-15 items to choose):

//[@id=“outboundF3”]/li[3]/div/span[2]
//
[@id=“outboundF8”]/li[3]/div/span[2]
//[@id=“outboundF0”]/li[3]/div/span[2]
//
[@id=“outboundF14”]/li[3]/div/span[2]
//[@id=“outboundF2”]/li[3]/div/span[2]
//
[@id=“outboundF1”]/li[3]/div/span[2]

They are not in chronological order in the page.
Not all numbers 1-15 exist, for example //*[@id=“outboundF7”]/li[3]/div/span[2] does not exist for this run
I loop from 1-15 and test the elements one by one, exist? present? visible? clickable?
I have tried all kind of combinations with
WebUI.waitForElementNotPresent
WebUI.waitForElementNotVisible
WebUI.waitForElementNotClickable

WebUI.waitForElementPresent
WebUI.waitForElementVisible
WebUI.waitForElementClickable

WebUI.verifyElementPresent
WebUI.verifyElementVisible
WebUI.verifyElementClickable
WebUI.verifyElementExist

to no avail

for (int j = 15; j >= 0; j--) {
    String xpathvariable = ('//*[@id="outboundF' + j) + '"]/li[3]/div/span[2]'
    SegmentX = WebUI.modifyObjectProperty(findTestObject('repository/object'), 'xpath', 'equals', xpathvariable, true)
    WebUI.delay(1)
    if (WebUI.waitForElementNotPresent(SegmentX, 2) == false) {
        maxSeconds = 1
        while ((maxSeconds < 60) && (((WebUI.waitForElementPresent(SegmentX, 4) == false) ||                                       (WebUI.waitForElementVisible(SegmentX, 4) == false)) ||                                       (WebUI.waitForElementClickable(SegmentX, 4) == false))) {
            WebUI.delay(1)
            maxSeconds++
        }
        
        WebUI.delay(3)
        if (WebUI.verifyElementClickable(SegmentX) == true) {
            WebUI.click(SegmentX)
            break
        }
    }
}

The “while” works fine and continues after 2-5 seconds
I would think that when if WebUI.verifyElementClickable(MYELEMENT) == true it is safe to click the element.

Unfortunately that is not the case, i get an error:

Test Cases/SAS Test Cases/SCRIPT FAILED because (of) Unable to click on object ‘Object Repository/REPOSITORY/OBJECT’ (Root cause: org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (913, 704). Other element would receive the click: …

I understand that the error is due to the object being conceiled behind other object, i.e. the object is present but not clickable. Then I cannot understand why if WebUI.verifyElementClickable(MYELEMENT) == true

I have tried this (pseudo code):

if (WebUI.click(ELEMENT, FailureHandling.OPTIONAL)) {
WebUI.comment(“Continue searching”)
} else {
click
break
}

To add insult to injury the error happens 2 times out of 10. For this reason I have added lots of Delay(5) here and there to no avail. The exact same test scenario with the exact same test environment clicks the element with no problem 8 times out of 10. This makes my Test Script very unreliable.

How can I test 100% that the element is clickable before clicking on it.

(I want to stress that I am Katalon rookie and want to use Katalon as it is intended: for non-programmers. Thanks)

3 Likes

I have solved this issue without using the unreliable “waitForElement …” functions.

Even if all the functions:

WebUI.waitForElementPresent
WebUI.waitForElementVisible
WebUI.waitForElementClickable

WebUI.verifyElementPresent
WebUI.verifyElementVisible
WebUI.verifyElementClickable
WebUI.verifyElementExist

return true, sometimes the element is not clickable. The error “Unable to click on object … Other element would receive the click” is due to the fact that sometimes the element is concealed behind another. but then I don’t understand why ‘ElementVisible’ and ‘ElementClickable’ return true. Very annoying that I must trig the error and catch it, instead of AVOIDING the scenario altogether. Now my logfile is polluted with errors but the script continues.

This is my solution:

loopcount = 0
errorcount = 0
while (loopcount == errorcount) {
String xpathvariable = ('//*[@id="outboundF' + loopcount) + '"]/li[3]/div/span[2]'
SegmentX = WebUI.modifyObjectProperty(findTestObject('Repository/Object'),                             'xpath', 'equals', xpathvariable, true)
try {
WebUI.click(SegmentX)
}
catch (Exception e) {
errorcount++
WebUI.comment('ERROR nr .' + errorcount + '. occurred (Could not click on >' + xpathvariable + '<)')
}
loopcount++
WebUI.comment('(LOOP ' + loopcount + ') ' + errorcount + ' ERRORS occurred')
if (loopcount > errorcount) {
WebUI.comment(('Clicked on .' + xpathvariable) + '. OK')
break
}
}
2 Likes

Why not wait for the obscuring element to be out of the way? Would that help? Do you even know what element is obscuring your target element?

Unfortunately not. I have profusely used delay to no avail, just making the script very slow.

Now with no waits I just click click click and in a couple of secs I find a clickable element.

Less elegant trigging the error than avoiding it, if they ask me. But I couldn’t find a better way.

Still find it annoying that ‘ElementClickable’ and ‘Element Visible’ don’t do their job.

Also (maybe this is incorrect) but when the script ended in error I could click by hand all elements-

Go figure.

1 Like

Have you tried multiple browsers? Do they all behave the same?

Chrome and FF. Different wording in error description but same root cause.