Issue:
WebUI.click() keyword sometimes is clickable and unclickable when executing the test in different environments.
Solution:
Since Selenium 3, the maximum browser is providing their respective browser driver, which implements WebDriver API. Selenium communicates to these browser drivers through HTTP commands, and these drivers speak natively with the browser. Official documentation of Selenium says:
“Selenium-WebDriver makes direct calls to the browser using each browser’s native support for automation. “
We can say that the way chrome browser allows a click on a web element may be different from other browsers.
Also, when we click on a WebElement using Selenium WebDriver, it checks two preconditions before clicking:
-
The element must be visible.
-
It must have a height and width greater than 0.
If preconditions are not satisfied, you will get exceptions stating the element is not clickable or interactable. Refer click() method in the official document here.
But in JavaScript clicks, do not check these preconditions before clicking. The method simulates a mouse click on an element. When click()
is used with supported elements (such as an <input>
), it fires the element's click event. Reference here.
So, JavaScript could click on a web element that may not be clickable by WebDriver API. Hence, to simulate actual user behavior, we should go for WebDriver and use JS sparingly and only when direct methods of WebDriver don't work.
We suggest using the JavascriptExecutor like the sample below instead of using the WebUI.click() keyword:
import com.kms.katalon.core.webui.common.WebUiCommonHelper as WebUiCommonHelperimport org.openqa.selenium.WebElement as WebElement
WebElement element = WebUiCommonHelper.findWebElement(findTestObject('your/object'),30) WebUI.executeJavaScript("arguments[0].click()", Arrays.asList(element))
Comments
0 comments
Please sign in to leave a comment.