Katalon Studio弹出元素识别

时间:2018-05-17 08:00:51

标签: selenium-webdriver webdriver frame katalon-studio katalon-recorder

我面临的以下问题可能是由于我对Selenese缺乏了解。这是我第一次使用Katalon Studio而且我对我所面临的问题感到非常困惑,因为它似乎正在使用Katalon Recorder,但导出的脚本并不适用于Studio。我很确定我需要更改我的代码,但我不知道是什么。

关于我的问题的以下详细信息来自我之前关于Katalon论坛的帖子,该帖子有截图以帮助澄清我的描述。您可以通过以下链接找到我的问题:https://forum.katalon.com/discussion/6746/popup-form-not-recognized#latest

弹出窗体无法识别

我正在公司网站上自动提交注册表单。

该表单的一部分中有一个按钮" Add HQ Address"需要点击

这将打开一个弹出窗口(我认为它叫做模态窗口),输入更多数据:

我使用的Selenium Studio 5.4.1无法关注这个新窗口,并继续说未找到相应的ID或索引。

为了您的信息,我使用Katalon Recorder IDE Chrome扩展程序记录填写此表单,然后在selenese中导出脚本以用于Katalon Studio。

selenium.click('id=_application_portlet_WAR_morcmsportlet_btnAddHQAddress')
selenium.selectFrame('index=0')
selenium.click('id=_application_portlet_WAR_morcmsportlet_postalTx')

错误发生在" index = 0'线。

这是控制台日志:

> `05-17-2018 04:32:39 PM - [START]  - Start Test Case : Test Cases/New Test Case 1
05-17-2018 04:32:39 PM - [INFO]   - Evaluating variables for test case
05-17-2018 04:32:40 PM - [START]  - Start action : openBrowser
05-17-2018 04:32:41 PM - [INFO]   - Opening browser
05-17-2018 04:32:41 PM - [INFO]   - Starting 'Chrome' driver
05-17-2018 04:32:41 PM - [INFO]   - Action delay is set to 0 seconds
Starting ChromeDriver 2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73) on port 3131
Only local connections are allowed.
May 17, 2018 4:32:51 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
05-17-2018 04:33:12 PM - [RUN_DATA] - Logging run data 'sessionId' with value '6ea4d9fdedc35b6cbe8830fc3aa58d10'
05-17-2018 04:33:12 PM - [RUN_DATA] - Logging run data 'browser' with value 'Chrome 66.0.3359.139'
05-17-2018 04:33:12 PM - [RUN_DATA] - Logging run data 'platform' with value 'Windows 7'
05-17-2018 04:33:12 PM - [RUN_DATA] - Logging run data 'seleniumVersion' with value '3.7.1'
05-17-2018 04:33:12 PM - [RUN_DATA] - Logging run data 'proxyInformation' with value 'ProxyInformation{proxyOption=USE_SYSTEM, proxyServerType=HTTP, password=, proxyServerAddress=, proxyServerPort=0}'
05-17-2018 04:33:12 PM - [INFO]   - Navigating browser to: 'https://mo-uat.nets.com.sg/group/main'
05-17-2018 04:33:16 PM - [PASSED] - Browser is opened with url: 'https://mo-uat.nets.com.sg/group/main'
05-17-2018 04:33:16 PM - [END]    - End action : openBrowser
05-17-2018 04:33:16 PM - [START]  - Start action : Statement - java.lang.System.setProperty("webdriver.chrome.driver", "C:\Users\vilvamanggkhai\Documents\Stuidio\chromedriver.exe")
05-17-2018 04:33:16 PM - [END]    - End action : Statement - java.lang.System.setProperty("webdriver.chrome.driver", "C:\Users\vilvamanggkhai\Documents\Stuidio\chromedriver.exe")
05-17-2018 04:33:16 PM - [START]  - Start action : Statement - driver = com.kms.katalon.core.webui.driver.DriverFactory.getWebDriver()
05-17-2018 04:33:16 PM - [END]    - End action : Statement - driver = com.kms.katalon.core.webui.driver.DriverFactory.getWebDriver()
05-17-2018 04:33:16 PM - [START]  - Start action : Statement - baseUrl = "https://mo-uat.nets.com.sg/group/main"
05-17-2018 04:33:16 PM - [END]    - End action : Statement - baseUrl = "https://mo-uat.nets.com.sg/group/main"
05-17-2018 04:33:16 PM - [START]  - Start action : Statement - selenium = new com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium(driver, baseUrl)
05-17-2018 04:33:16 PM - [END]    - End action : Statement - selenium = new com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium(driver, baseUrl)
05-17-2018 04:33:16 PM - [START]  - Start action : Statement - selenium.click("id=_58_login")
05-17-2018 04:33:16 PM - [END]    - End action : Statement - selenium.click("id=_58_login")
05-17-2018 04:33:16 PM - [START]  - Start action : Statement - selenium.type("id=_58_login", "css.verifier1")
05-17-2018 04:33:16 PM - [END]    - End action : Statement - selenium.type("id=_58_login", "css.verifier1")
05-17-2018 04:33:16 PM - [START]  - Start action : Statement - selenium.click("id=_58_password")
05-17-2018 04:33:16 PM - [END]    - End action : Statement - selenium.click("id=_58_password")
05-17-2018 04:33:16 PM - [START]  - Start action : Statement - selenium.type("id=_58_password", "P@ssw0rd")
05-17-2018 04:33:16 PM - [END]    - End action : Statement - selenium.type("id=_58_password", "P@ssw0rd")
05-17-2018 04:33:16 PM - [START]  - Start action : Statement - selenium.click("//button[@type='submit']")
05-17-2018 04:33:23 PM - [END]    - End action : Statement - selenium.click("//button[@type='submit']")
05-17-2018 04:33:23 PM - [START]  - Start action : Statement - selenium.open("https://mo-uat.nets.com.sg/group/main/create-application")
05-17-2018 04:33:25 PM - [END]    - End action : Statement - selenium.open("https://mo-uat.nets.com.sg/group/main/create-application")
05-17-2018 04:33:25 PM - [START]  - Start action : Statement - selenium.open("https://mo-uat.nets.com.sg/group/main/create-application?p_p_id=application_portlet_WAR_morcmsportlet&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_application_portlet_WAR_morcmsportlet_showTab=Application&_application_portlet_WAR_morcmsportlet_render=createAppLoadCustomer")
05-17-2018 04:33:26 PM - [END]    - End action : Statement - selenium.open("https://mo-uat.nets.com.sg/group/main/create-application?p_p_id=application_portlet_WAR_morcmsportlet&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_application_portlet_WAR_morcmsportlet_showTab=Application&_application_portlet_WAR_morcmsportlet_render=createAppLoadCustomer")
05-17-2018 04:33:26 PM - [START]  - Start action : Statement - selenium.type("id=_application_portlet_WAR_morcmsportlet_custIdNo", "oijl78g84")
05-17-2018 04:33:26 PM - [END]    - End action : Statement - selenium.type("id=_application_portlet_WAR_morcmsportlet_custIdNo", "oijl78g84")
05-17-2018 04:33:26 PM - [START]  - Start action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_custIdType")
05-17-2018 04:33:26 PM - [END]    - End action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_custIdType")
05-17-2018 04:33:26 PM - [START]  - Start action : Statement - selenium.select("id=_application_portlet_WAR_morcmsportlet_custIdType", "label=ACRA")
05-17-2018 04:33:27 PM - [END]    - End action : Statement - selenium.select("id=_application_portlet_WAR_morcmsportlet_custIdType", "label=ACRA")
05-17-2018 04:33:27 PM - [START]  - Start action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_custIdType")
05-17-2018 04:33:27 PM - [END]    - End action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_custIdType")
05-17-2018 04:33:27 PM - [START]  - Start action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_btnProceed")
05-17-2018 04:33:30 PM - [END]    - End action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_btnProceed")
05-17-2018 04:33:30 PM - [START]  - Start action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_salesConsultantCd")
05-17-2018 04:33:30 PM - [END]    - End action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_salesConsultantCd")
05-17-2018 04:33:30 PM - [START]  - Start action : Statement - selenium.select("id=_application_portlet_WAR_morcmsportlet_salesConsultantCd", "label=VALERIE CHEE HSIN YEE")
05-17-2018 04:33:31 PM - [END]    - End action : Statement - selenium.select("id=_application_portlet_WAR_morcmsportlet_salesConsultantCd", "label=VALERIE CHEE HSIN YEE")
05-17-2018 04:33:31 PM - [START]  - Start action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_salesConsultantCd")
05-17-2018 04:33:31 PM - [END]    - End action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_salesConsultantCd")
05-17-2018 04:33:31 PM - [START]  - Start action : Statement - selenium.click("Xpath=//*[contains(text(),' Profile ')]")
05-17-2018 04:33:31 PM - [END]    - End action : Statement - selenium.click("Xpath=//*[contains(text(),' Profile ')]")
05-17-2018 04:33:31 PM - [START]  - Start action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_custNameTx")
05-17-2018 04:33:31 PM - [END]    - End action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_custNameTx")
05-17-2018 04:33:31 PM - [START]  - Start action : Statement - selenium.type("id=_application_portlet_WAR_morcmsportlet_custNameTx", "company name")
05-17-2018 04:33:31 PM - [END]    - End action : Statement - selenium.type("id=_application_portlet_WAR_morcmsportlet_custNameTx", "company name")
05-17-2018 04:33:31 PM - [START]  - Start action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_businessTypeCd")
05-17-2018 04:33:32 PM - [END]    - End action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_businessTypeCd")
05-17-2018 04:33:32 PM - [START]  - Start action : Statement - selenium.select("id=_application_portlet_WAR_morcmsportlet_businessTypeCd", "label=PTE LTD")
05-17-2018 04:33:32 PM - [END]    - End action : Statement - selenium.select("id=_application_portlet_WAR_morcmsportlet_businessTypeCd", "label=PTE LTD")
05-17-2018 04:33:32 PM - [START]  - Start action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_businessTypeCd")
05-17-2018 04:33:32 PM - [END]    - End action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_businessTypeCd")
05-17-2018 04:33:32 PM - [START]  - Start action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_custDt_corp")
05-17-2018 04:33:33 PM - [END]    - End action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_custDt_corp")
05-17-2018 04:33:33 PM - [START]  - Start action : Statement - selenium.type("id=_application_portlet_WAR_morcmsportlet_custDt_corp", "07/05/2018")
05-17-2018 04:33:33 PM - [END]    - End action : Statement - selenium.type("id=_application_portlet_WAR_morcmsportlet_custDt_corp", "07/05/2018")
05-17-2018 04:33:33 PM - [START]  - Start action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_btnAddHQAddress")
05-17-2018 04:33:33 PM - [END]    - End action : Statement - selenium.click("id=_application_portlet_WAR_morcmsportlet_btnAddHQAddress")
05-17-2018 04:33:33 PM - [START]  - Start action : Statement - selenium.selectFrame("index=0")
05-17-2018 04:33:33 PM - [END]    - End action : Statement - selenium.selectFrame("index=0")
05-17-2018 04:33:33 PM - [ERROR]  - Test Cases/New Test Case 1 FAILED because (of) com.thoughtworks.selenium.SeleniumException: no such frame
  (Session info: chrome=66.0.3359.139)
  (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 6.1.7601 SP1 x86) (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: 'NB7INTERN18M', ip: '176.175.12.39', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', 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.528161 (5b82f2d2aae0ca..., userDataDir: C:\Users\vilvamanggkhai\App...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 66.0.3359.139, webStorageEnabled: true}
Session ID: 6ea4d9fdedc35b6cbe8830fc3aa58d10
05-17-2018 04:33:33 PM - [END]    - End Test Case : Test Cases/New Test Case 1`

这是错误消息:

> `Test Cases/New Test Case 1 FAILED because (of) com.thoughtworks.selenium.SeleniumException: no such frame
  (Session info: chrome=66.0.3359.139)
  (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 6.1.7601 SP1 x86) (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: 'NB7INTERN18M', ip: '176.175.12.39', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', 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.528161 (5b82f2d2aae0ca..., userDataDir: C:\Users\vilvamanggkhai\App...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 66.0.3359.139, webStorageEnabled: true}
Session ID: 6ea4d9fdedc35b6cbe8830fc3aa58d10

Test Cases/New Test Case 1.run:87`

1 个答案:

答案 0 :(得分:2)

此错误消息......

05-17-2018 04:33:33 PM - [ERROR]  - Test Cases/New Test Case 1 FAILED because (of) com.thoughtworks.selenium.SeleniumException: no such frame
  (Session info: chrome=66.0.3359.139)
  (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 6.1.7601 SP1 x86) (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'

...暗示 ChromeDriver 无法找到所需的框架并引发 SeleniumException:没有此类框架

这里有三个问题如下:

您已在元素上调用click(),切换 frame 并在框架内背靠背调用click(),如下所示:

selenium.click('id=_application_portlet_WAR_morcmsportlet_btnAddHQAddress')
selenium.selectFrame('index=0')
selenium.click('id=_application_portlet_WAR_morcmsportlet_postalTx')

理想情况下,一旦您click()打开所需框架的元素切换到框架,您需要为框架引导 WebDriverWait 可用,然后切换到它,如下所示( Python版本):

#WebDriverWait for frame_to_be_available_and_switch_to_it
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it(By.ID,"id_of_iframe"))
#or
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it(By.NAME,"name_of_iframe"))

在这里,您将找到有关How can I select a html element no matter what frame it is in in selenium?

的详细讨论

继续前进,要再次对框架内的元素调用click(),您必须为元素引导 WebDriverwait ,如下所示( Python版):

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "elementID"))).click()

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

  • 您正在使用 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 有点旧。< / LI>

因此 Selenium Client v3.7.1 ChromeDriver v2.35 Chrome浏览器v66.0 <之间存在明显的不匹配/ p>

解决方案

  • 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