Skip to content Skip to sidebar Skip to footer

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 Stud

Solution 1:

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

Solution 2:

((JavascriptExecutor) DriverFactory.webDriver).executeScript('Your JavaScript-Code', argument);

Solution 3:

You can try using a custom keyword, inside of the package "yourPackage":

@KeywordstaticclickJS(TestObject to, int timeout) {
    WebUI.waitForElementVisible(to, timeout)
    try {
        WebUI.click(to)
    }
    catch (Exception e) {
        WebDriverdriver= DriverFactory.getWebDriver()
        WebElementelement= WebUiCommonHelper.findWebElement(to, timeout)
        JavascriptExecutorexecutor= ((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"))

Post a Comment for "How Can I Use Javascript In Katalon Studio?"