1

I am trying to set a new data value of a custom attribute of a div using attr() while going through this, I found out it can be done using .attr( attributeName, value )

I have a requirement wherein I want to change the attribute value of DOM before a particular ajax call. Now how can I call this jQuery in Katalon to change the DOM element?

I am trying to implement the solution from this post in Katalon.

[1]:

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
Tarun Das
  • 131
  • 9

1 Answers1

1

you can create a CustomKeyword and add this generic method:

@Keyword
def execJS(String script){
    WebDriver driver = DriverFactory.getWebDriver()
    JavascriptExecutor jse = (JavascriptExecutor)driver;
    jse.executeScript(script)
    sleep(300)
}

then you can use your JavaScript code in the TestCase typing CustomKeywords:

//use jQuery intead of $ symbol
String myJsScript = "jQuery('input').attr('disabled', true)"
CustomKeywords.'utils.myutils.MyUtils.execJS'(myJsScript)

NB: jquery must be imported in the page you're testing.

raffaeleambrosio
  • 235
  • 2
  • 11