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)