在Javascript中使用时,Katalon Studio创建的元素与webDriver无法识别

时间:2018-05-25 14:05:35

标签: javascript selenium selenium-webdriver webdriver katalon-studio

我试图在Katalon Studio中使用executeJavascript方法,并编写了几行代码,看起来与文档示例中的代码非常相似:

文档示例: enter image description here

我的剧本: enter image description here

我还在我的脚本中导入了WebElement:

enter image description here

但是,当我运行测试时,我收到以下错误消息:

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

然后,我更新了我的selenium,chr​​ome驱动程序和java,但我仍然收到此错误:

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)

我不明白为什么我仍然会收到此错误,以及我如何解决此错误。

1 个答案:

答案 0 :(得分:0)

此错误消息......

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

...表示 ChromeDriver 无法与浏览上下文 Chrome浏览器会话进行通信。

您的主要问题是您使用的二进制文件之间的版本兼容性,如下所示:

  • 您正在使用 chromedriver = 2.35
  • chromedriver=2.35的发行说明明确提及以下内容:
  

支持 Chrome v62-64

  • 您正在使用 chrome = 66.0
  • ChromeDriver v2.38的发行说明明确提及以下内容:
  

支持 Chrome v65-67

  • 您的 Selenium客户端 2017-11-06T21:07:36.161Z 3.7.1 ,差不多是的一半年年长。
  • 您的 JDK版 1.8.0_102 ,这很古老。

因此 JDK v8u102 Selenium客户端 v3.7.1 ChromeDriver 版 v2.35 Chrome浏览器 v66.0

解决方案

  • JDK 升级到最近的级别JDK 8u171
  • Selenium 升级到当前级别Version 3.12.0
  • ChromeDriver 升级到当前ChromeDriver v2.38级别。
  • Chrome 版本保留在 Chrome v66.x 级别。 (as per ChromeDriver v2.38 release notes
  • 通过 IDE 清理您的项目工作区仅使用所需的依赖项重建项目
  • 使用CCleaner工具清除执行测试套件之前和之后的所有操作系统杂务。
  • 如果您的基本 Web客户端版本太旧,请通过Revo Uninstaller将其卸载并安装最新的GA和已发布的 Web客户端版本。
  • 进行系统重启
  • 执行@Test