# Bug with keyword Execute JavaScript

**URL:** <https://forum.katalon.com/t/bug-with-keyword-execute-javascript/25386>\
**Category:** Bug Report\
**Tags:** bugs-report, katalon-studio\
**Created:** [May 15, 2019, 12:15pm UTC](https://forum.katalon.com/t/bug-with-keyword-execute-javascript/25386 "2019-05-15T12:15:13Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roman\_Pankov](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/roman_pankov/32/490_2.png) [@Roman\_Pankov](https://forum.katalon.com/u/Roman_Pankov)\
**Post date:** [May 15, 2019, 12:15pm UTC](https://forum.katalon.com/t/bug-with-keyword-execute-javascript/25386/1 "2019-05-15T12:15:13Z")

</div>

There some bug with keyword Execute Javascript

I need to use in without arguments  
When I try to do it for the first time and write this:

`def ForAssert = WebUI.executeJavaScript(findTestData('JavaScriptHelper').getValue(1, 1), null)`

After save and run test working normal, but after close test, open it again I see this

```
Caused by: com.kms.katalon.core.exception.StepFailedException: Unable to execute JavaScript.
	... 19 more
Caused by: org.openqa.selenium.WebDriverException: unknown error: Cannot read property 'value' of null

```

Here when I open the keyword

 ![error1](https://europe1.discourse-cdn.com/katalon/original/2X/0/0749e967a3602168ca51ee0c338a6fb0c2113583.png)

I think this is bug, please fix it

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [May 15, 2019, 3:37pm UTC](https://forum.katalon.com/t/bug-with-keyword-execute-javascript/25386/2 "2019-05-15T15:37:37Z")

</div>

(Moved this from the Katalon Analytics category to the more appropriate Katalon Studio category.)

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [May 15, 2019, 3:42pm UTC](https://forum.katalon.com/t/bug-with-keyword-execute-javascript/25386/3 "2019-05-15T15:42:25Z")

</div>

Looking at this part of the error:

> [@Roman\_Pankov](#):
>
> Caused by: org.openqa.selenium.WebDriverException: unknown error: Cannot read property ‘value’ of null

your problem actually isn’t the `null` argument. What’s happening is that `findTestData('JavaScriptHelper')` is returning `null`. Please make sure that you have a data file at the location you’ve specified.

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [May 15, 2019, 3:48pm UTC](https://forum.katalon.com/t/bug-with-keyword-execute-javascript/25386/4 "2019-05-15T15:48:28Z")

</div>

Also, I don’t understand your use of the WebUI.executeJavaScript() method here… Usually you use this method to do exactly that; execute some **JS code** , for example:

`WebUI.executeJavaScript("console.log('Hello world!')", null)`

Trying to execute:

`findTestData('JavaScriptHelper').getValue(1, 1)`

as JS code doesn’t make any sense. Unless the value you are expecting to be returned by getValue(1, 1) is a JS code snippet, which is fine, if not a little odd…

---

<div class="post-metadata">

**Author:** ![hpulsford](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/hpulsford/32/2985_2.png) [@hpulsford](https://forum.katalon.com/u/hpulsford)\
**Post date:** [May 15, 2019, 3:55pm UTC](https://forum.katalon.com/t/bug-with-keyword-execute-javascript/25386/5 "2019-05-15T15:55:00Z")

</div>

If your just trying to get the value from a data file just follow this instead of using js. Not sure why you are even attempting to use JS

```auto
//get data
def data = findTestData('Data Files/DB Data')
// Get specific data (column, row) as a variable
String record = data.getValue(3, 4)
//print my variable
println record

```

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [May 15, 2019, 4:11pm UTC](https://forum.katalon.com/t/bug-with-keyword-execute-javascript/25386/6 "2019-05-15T16:11:20Z")

</div>

Well, `findTestData` returns a `TestData` object (interface actually). Methinks here endeth the story.

[https://api-docs.katalon.com/com/kms/katalon/core/testdata/TestDataFactory.html#findTestData(java.lang.String)](https://api-docs.katalon.com/com/kms/katalon/core/testdata/TestDataFactory.html#findTestData(java.lang.String))

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [May 15, 2019, 4:13pm UTC](https://forum.katalon.com/t/bug-with-keyword-execute-javascript/25386/7 "2019-05-15T16:13:14Z")

</div>

> [@Russ\_Thomas](#):
>
> Well, `findTestData` returns a `TestData` object (interface actually).

Right, but then he’s doing getValue(1, 1), which returns whatever is in the first cell of the Test Data as a String, which could be a JS code snippet.

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [May 15, 2019, 4:16pm UTC](https://forum.katalon.com/t/bug-with-keyword-execute-javascript/25386/8 "2019-05-15T16:16:55Z")

</div>

Which would be exceedingly…

Well, let’s leave it there 😕

---

<div class="post-metadata">

**Author:** ![Roman\_Pankov](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/roman_pankov/32/490_2.png) [@Roman\_Pankov](https://forum.katalon.com/u/Roman_Pankov)\
**Post date:** [May 15, 2019, 4:49pm UTC](https://forum.katalon.com/t/bug-with-keyword-execute-javascript/25386/9 "2019-05-15T16:49:34Z")

</div>

I know what happen.  
I write case (in data file stored JS code snippet) I need this.  
I see that Execute JS need arguments, but I don’t have them, I read docs, and see that i need to write like this

`WebUI.executeJavaScript("return alert("Hello world"), null)`

Ok, write it, run it’s work, great  
I save test case, next day open project, open test case and try to run it again. And got this error.

This works only for the first time, after save, reopen test case it not working.

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/katalon/original/3X/d/5/d55596ab02785a255798e87ede769734747b30c4.svg) [@system](https://forum.katalon.com/u/system)\
**Post date:** [May 14, 2020, 5:00pm UTC](https://forum.katalon.com/t/bug-with-keyword-execute-javascript/25386/10 "2020-05-14T17:00:05Z")

</div>

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
