-1

In Katalon Studio, I have created a test whereby at some point I want to change an element's background colour to blue. I use this instruction in my script:

WebUI.executeJavaScript('document.querySelector(\'.content-header\').setAttribute(\'background\', \'blue\')', null)

and when I run the test, I get this in the Log Viewer:

enter image description here

So it seems the Javascript executed successfully.. but then why didn't I see any change in the browser? Shouldn't the change occur and then continue until the test is complete? Is it, in fact, not actually working?

user74843
  • 701
  • 2
  • 10
  • 28

1 Answers1

0

To set the style.background attribute to blue you can use the following code block :

WebElement elem = WebUiCommonHelper.findWebElement(findTestObject('your/object'),30)
String js = "arguments[0].style.background='blue';";
WebUI.executeJavaScript(js, elem);
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • when i try this, i get this error message: FAILED because (of) Variable 'WebUiCommonHelper' is not defined for test case. – user74843 May 25 '18 at 15:15
  • okay, now i have import webuicommon helper like this - import com.kms.katalon.core.webui.common.WebUiCommonHelper , but now i get this error message: fill in maintenance request form FAILED because (of) java.lang.NullPointerException – user74843 May 25 '18 at 15:19
  • @user74843 I am not exactly sure how _WebElement_ is identified in _Katalon-Studio_, but I have referred to the snapshot you have provided in the other QA/Discussion [Katalon Studio creating element with webDriver not recognised when used in Javascript](https://stackoverflow.com/questions/50531015/katalon-studio-creating-element-with-webdriver-not-recognised-when-used-in-javas) – undetected Selenium May 25 '18 at 15:19
  • 1
    i identified the web element, but now i have this error :/ FAILED because (of) groovy.lang.MissingMethodException: No signature of method – user74843 May 25 '18 at 15:30