Automatic filter error

Hi, I need to create a TC in which I filter a table by setting some text in a text box and then click on the element that appears after I filter.
In my TC I enter a page and then the text I need, Then the page automatically filters the info in the table with out me pressing enter. The thing is that Katalon does not make this so whenever I do a click action, it does not click the element I want.

This is the way in which I filter in the TC:
.
.
.
CustomKeywords.‘keywordPrueba.CustomFunction.clickUsingJS’(findTestObject(‘Object Repository/Page_Pruebas/input_Prueba Descripcion1_vPRUEBADESCRIPCION1’),
30)

WebUI.executeJavaScript(‘arguments[0].value='NITRITOS EN ORINA'’, Arrays.asList(elementPrueba))

WebUI.delay(3) //I do this to wait for the table to be properly filtered but nothing happens
.
.
.
So apart from the delay I also tried waiting for the new table to appear but it does not work. Any other suggestions?

Here is the filter with its text box and its html and the table I want to filter:

This is what it should happen:

Try this…

String js = '''
  arguments[0].value='NITRITOS EN ORINA';
  arguments[0].onchange();
'''
WebUI.executeJavaScript(js, Arrays.asList(elementPrueba))

WebUI.delay(3) 

Thanks for the quick answer
After I do exactly that this is the error I am facing:

10: js = "
arguments[0].value=‘NITRITOS EN ORINA’;
arguments[0].onchange();
"
2019-07-24 11:01:52.023 DEBUG testcase.NoImprimeEnInforme - 11: executeJavaScript(js, Arrays.asList(elementPrueba))
2019-07-24 11:01:52.406 ERROR c.k.k.core.keyword.internal.KeywordMain - :x: Unable to execute JavaScript. (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to execute JavaScript.
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.executeJavascript(ExecuteJavascriptKeyword.groovy:42)
at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.execute(ExecuteJavascriptKeyword.groovy:37)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.executeJavaScript(WebUiBuiltInKeywords.groovy:3787)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$executeJavaScript$4.call(Unknown Source)
at NoImprimeEnInforme.run(NoImprimeEnInforme:52)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1563976894373.run(TempTestCase1563976894373.groovy:21)
Caused by: org.openqa.selenium.WebDriverException: unknown error: Runtime.evaluate threw exception: SyntaxError: Invalid or unexpected token

The JavaScript contains an error. In my example there are THREE single quotes surrounding the JavaScript code. Your pasted copy doesn’t contain them:

''' three single quotes to wrap JS '''

So now it sets “nitritos en orina” in the text box but then continues to fail

The quotes appear doble in the console but I use three single quotes in the script

This are the errors:

2019-07-24 11:20:39.313 DEBUG testcase.NoImprimeEnInforme - 11: executeJavaScript(js, Arrays.asList(elementPrueba))
2019-07-24 11:20:39.622 ERROR c.k.k.core.keyword.internal.KeywordMain - :x: Unable to execute JavaScript.

Caused by: org.openqa.selenium.JavascriptException: javascript error: Cannot read property ‘getValidStructFld’ of null

That’s a new reference to me. Help me by showing what that is. I suspect you have a line of JS code somewhere that looks something like this:

something.getValidStructFld();

… and “something” is null.

If you are only supplying the JavaScript code as I supplied it to you, then it is likely that the call to onchange() is causing the problem.

You could try a different tack… use WebUI.sendKeys.

Once again, thanks for the reply
1)
In regards to ¨getValidStructFld¨ the entire error in the console is like this:

com.kms.katalon.core.exception.StepFailedException: Unable to execute JavaScript.
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.executeJavascript(ExecuteJavascriptKeyword.groovy:42)
at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.execute(ExecuteJavascriptKeyword.groovy:37)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.executeJavaScript(WebUiBuiltInKeywords.groovy:3787)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$executeJavaScript$4.call(Unknown Source)
at NoImprimeEnInforme.run(NoImprimeEnInforme:53)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1563978022921.run(TempTestCase1563978022921.groovy:21)
Caused by: org.openqa.selenium.JavascriptException: javascript error: Cannot read property ‘getValidStructFld’ of null
I do not have something like this in my code: something.getValidStructFld();
2) I do think its caused by onChange
3) What do you mean by this:
You could try a different tack… use WebUI.sendKeys .
Ive tried to simulate an ENTER by using send keys before but nothing happens. I mean, the filtered table should appear while you are typing whatever you need to set in the text box of the filter

If sendKeys didn’t work for you, let’s not go that route.

Okay, we’re clearly shooting in the dark here.

String js = '''
  arguments[0].value='NITRITOS EN ORINA';
  arguments[0].blur();
'''
WebUI.executeJavaScript(js, Arrays.asList(elementPrueba))

If that doesn’t work, I’d seriously reconsider sendKeys.

Ok so if I use blur it does not give me an error but it does nothing.
In regards to sendKeys, I tried to use it once again and it says that the element is not interactable.

The filter part should work but I could try clicking any other element without filtering. I mean, i am really confused by this problem. The first time I recorded it… it worked perfectly.

Which usually means you’re not waiting long enough for the element to be initialized properly.

I considered that. Click something after the field is filled with your filter. But really, it shouldn’t be this complicated.

Regarding blur/onchange - it now seems that the event in question is using something higher up in the hierarchy. What that is, is difficult to say. If you’re determined to get this right, here’s what I would do.

  1. Switch to Firefox.
  2. Inspect the element.
  3. When Firefox shows the element, look for event at the end of the line.
  4. Click on event, take a screenshot, post it here.

If there’s no event attached to that element, look for the nearest ancestor element and follow the steps above again.

1 Like

OMG !!! It worked !! You are a genius.
It told me element was not interactable. Then you told me it was because I was not waiting long enough so I did that and it worked.
Thank you very much !

1 Like