0

I'm trying to use the executeJavascript method in Katalon Studio, and having written a couple lines of code that look really similar to that in the documentation example:

documentation example: enter image description here

my script: enter image description here

I have also imported WebElement in my script:

enter image description here

However, when I run my test I get this error message:

Test Cases/Forms/Test1 - fill in maintenance request form FAILED because (of) Unable to execute JavaScript. (Root cause: org.openqa.selenium.WebDriverException: unknown error: element is not defined
(Session info: chrome=66.0.3359.181)
(Driver info: chromedriver=2.35.528157 (4429ca2590d6988c0745c24c8858745aaaec01ef),platform=Mac OS X 10.13.4 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:07:36.161Z'
System info: host: 'Nikkis-MacBook-Pro.local', ip: 'fe80:0:0:0:18e2:b2c7:8b31:3164%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_102'
Driver info: com.kms.katalon.selenium.driver.CChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.35.528157 (4429ca2590d698..., userDataDir: /var/folders/fl/d70hxqb520v...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 66.0.3359.181, webStorageEnabled: true}
Session ID: 05ebb4c39e0862af7f3893c442527a3b)

Test Cases/Forms/Test1 - fill in maintenance request form.run:65

then, I updated my selenium, chrome driver and java, but I still get this error:

Unable to execute JavaScript. (Root cause: org.openqa.selenium.WebDriverException: unknown error: element is not defined   (Session info: chrome=66.0.3359.181)   (Driver info: chromedriver=2.38.552518 (183d19265345f54ce39cbb94cf81ba5f15905011),platform=Mac OS X 10.13.4 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:08.936Z' System info: host: 'Nikkis-MacBook-Pro.local', ip: 'fe80:0:0:0:18e2:b2c7:8b31:3164%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_102' Driver info: com.kms.katalon.selenium.driver.CChromeDriver Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.38.552518 (183d19265345f5..., userDataDir: /var/folders/fl/d70hxqb520v...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: MAC, platformName: MAC, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version:
66.0.3359.181, webStorageEnabled: true} Session ID: 2c4f4643acb4d1c0a106ac0fb9e31254)

I don't understand why i am still getting this error, and how i can fix this.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
user74843
  • 701
  • 2
  • 10
  • 28

1 Answers1

0

This error message...

org.openqa.selenium.WebDriverException: unknown error: element is not defined

...implies that the ChromeDriver was unable to communicate with the Browsing Context i.e. Chrome Browser session.

Your main issue is the version compatibility between the binaries you are using as follows :

  • You are using chromedriver=2.35
  • Release Notes of chromedriver=2.35 clearly mentions the following :

Supports Chrome v62-64

  • You are using chrome=66.0
  • Release Notes of ChromeDriver v2.38 clearly mentions the following :

Supports Chrome v65-67

  • Your Selenium Client version is 3.7.1 of 2017-11-06T21:07:36.161Z which is almost half year older.
  • Your JDK version is 1.8.0_102 which is pretty ancient.

So there is a clear mismatch between the JDK v8u102, Selenium Client v3.7.1 , ChromeDriver version v2.35 and the Chrome Browser v66.0

Solution

  • Upgrade JDK to recent levels JDK 8u171.
  • Upgrade Selenium to current levels Version 3.12.0.
  • Upgrade ChromeDriver to current ChromeDriver v2.38 level.
  • Keep Chrome version at Chrome v66.x levels. (as per ChromeDriver v2.38 release notes)
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • Use CCleaner tool to wipe off all the OS chores before and after the execution of your test Suite.
  • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Execute your @Test.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • you said '...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowsing Session i.e. Chrome Browser session.', but a new chrome browser did open up to run the test - is this not what you meant?? – user74843 May 25 '18 at 14:27
  • Hmmm, typo got corrected. Updated my Answer. Let me know the status. – undetected Selenium May 25 '18 at 14:30
  • could you please describe how to carry out this step: Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only. – user74843 May 25 '18 at 15:08
  • @user74843 This step is to be performed from the IDE i.e. _Eclipse_, _PyCharm_, _SublimeText3_ to clear the IDE cache. I am not sure about _Katalon-Studio_ but there must be an option to **Rebuild** the entire project afresh. – undetected Selenium May 25 '18 at 15:11
  • hay, I updated my selenium, chrome driver and java. you can see the updated versions are being used in the edited post (i have edited the post with updates). However, I am still getting the error message... – user74843 May 25 '18 at 15:37
  • @user74843 Remove the `blockquotes` from the error trace logs within your question else the logs gets truncated and debugging becomes difficult – undetected Selenium May 25 '18 at 15:39
  • sorry, okay. btw, i'm not sure if this makes a difference, but if i try to execute a line in my script like this: WebUI.executeJavaScript("alert('This is an alert')", null), it works! Does this change anything? – user74843 May 25 '18 at 15:44
  • @user74843 Your _JDK_ version is still **'1.8.0_102'** which is pretty ancient :) – undetected Selenium May 25 '18 at 15:48
  • oh no! How can i change the JDK version? I downloaded the newest version - 1.8.0_172, but when I run a test using katalon studio it still seems to be using 1.8.0_102. I know how to change selenium and the chrome driver version, using this article https://docs.katalon.com/display/KD/Update+or+Replace+Web+Browser+Drivers+and+Selenium, but I don't know how to change the java file.. – user74843 May 28 '18 at 08:21