Sometimes, I encounter an element which I'm unable to click with a normal Selenium script so I have to use javascript to execute my script.
How can I use JavaScript in Katalon Studio?
Sometimes, I encounter an element which I'm unable to click with a normal Selenium script so I have to use javascript to execute my script.
How can I use JavaScript in Katalon Studio?
I believe you mean, Executng the Javascript code and get the element. You can try this appraoch - https://docs.katalon.com/display/KD/%5BWebUI%5D+Execute+JavaScript
((JavascriptExecutor) DriverFactory.webDriver).executeScript('Your JavaScript-Code', argument);
You can try using a custom keyword, inside of the package "yourPackage":
@Keyword
static clickJS (TestObject to, int timeout) {
WebUI.waitForElementVisible(to, timeout)
try {
WebUI.click(to)
}
catch (Exception e) {
WebDriver driver = DriverFactory.getWebDriver()
WebElement element = WebUiCommonHelper.findWebElement(to, timeout)
JavascriptExecutor executor = ((driver) as JavascriptExecutor)
executor.executeScript('arguments[0].click()', element)
}
throw(e)
}
Then, you can call the function inside your test script with:
CustomKeyords.'yourPackage.yourClass.clickJS'(findTestObject("yourObject"))