使用 Selenium IDE 在富文本编辑器中输入字符 [英] Typing characters in rich text editor using Selenium IDE

查看:162
本文介绍了使用 Selenium IDE 在富文本编辑器中输入字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在 Salesforce 应用程序中设置自动化测试,但在使用 Selenium IDE 的富文本编辑器中输入字符时遇到问题.

I'm currently setting up an automation testing in Salesforce application but I am having a problem of typing characters in rich text editor using Selenium IDE.

据我所知,富文本编辑器包含在 iframe 中.在 HTML 中,我得到了这样的代码:

As I know that the rich text editor is wrapped in the iframe. In the HTML, I got the code like this:

<iframe id="j_id0:j_id4:j_id6:j_id115:j_id117:textAreaDelegate_Comments__c_frame"     
frameborder="0" allowtransparency="true" tabindex="0" src="" title="Rich text editor, 
j_id0:j_id4:j_id6:j_id115:j_id117:textAreaDelegate_Comments__c, press ALT 0 for help." 
style="width:100%;height:100%">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org
/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html class="CSS1Compat" lang="en" dir="ltr" style="background-color: transparent;">
<head>
<body id="j_id0:j_id4:j_id6:j_id115:j_id117:textAreaDelegate_Comments__c_rta_body"   
class="cke_show_borders" contenteditable="true" spellcheck="false" style="background-
color: transparent;">
</html>

</iframe>

我目前的步骤是:

  1. 命令:selectFrame,目标:xpath=//*[contains (@id, 'j_id0:j_id4:j_id6:j_id115:j_id117:textAreaDelegate_Comments__c_frame')]
  2. 命令:点击,目标:xpath=//*[contains (@id, 'j_id0:j_id4:j_id6:j_id115:j_id117:textAreaDelegate_Comments__c_rta_body')]
  3. 命令:焦点,目标:xpath=//*[contains (@id, 'j_id0:j_id4:j_id6:j_id115:j_id117:textAreaDelegate_Comments__c_rta_body')]
  4. 命令:sendKeys,目标:xpath=//*[contains (@id, 'j_id0:j_id4:j_id6:j_id115:j_id117:textAreaDelegate_Comments__c_rta_body')], :在富文本编辑器中输入值!!!
  1. Command: selectFrame, Target: xpath=//*[contains (@id, 'j_id0:j_id4:j_id6:j_id115:j_id117:textAreaDelegate_Comments__c_frame')]
  2. Command: click, Target: xpath=//*[contains (@id, 'j_id0:j_id4:j_id6:j_id115:j_id117:textAreaDelegate_Comments__c_rta_body')]
  3. Command: focus, Target: xpath=//*[contains (@id, 'j_id0:j_id4:j_id6:j_id115:j_id117:textAreaDelegate_Comments__c_rta_body')]
  4. Command: sendKeys, Target: xpath=//*[contains (@id, 'j_id0:j_id4:j_id6:j_id115:j_id117:textAreaDelegate_Comments__c_rta_body')], Value: Input Value in Rich Text Editor!!!

当我运行此测试用例时,在步骤 4 中出现以下错误 - 意外异常:错误:无法设置选择结束.文件名 ->chrome://selenium-ide/content/selenium-core/scripts/atoms.js, lineNumber ->6118,列号->6.我不知道我做错了什么,为什么我无法使用 Selenium IDE 在富文本编辑器中输入字符.

When I ran this test case, and I got the following error in step 4 - Unexpected Exception: Error: Cannot set the selection end. fileName -> chrome://selenium-ide/content/selenium-core/scripts/atoms.js, lineNumber -> 6118, columnNumber -> 6. I didn't know what did I do wrong and why I couldn't typing characters in rich text editor using Selenium IDE.

谢谢

推荐答案

如果可以选择 contentEditable 元素,则可以设置其内部 HTML.

If you can select the contentEditable element, you can set its inner HTML.

在 Selenium IDE 中,我在测试套件的顶部有一个帮助程序测试,其中包含帮助程序命令以使此类操作更加方便.

In Selenium IDE, I have a helper test at the top of my test suites that contains helper commands to make things like this a little more convenient.

命令: storeEval,目标:Selenium.prototype.doInnerHTML=function(locator,text){var element=this.browserbot.findElement(locator);if(element===null)return null;element.innerHTML=text}

Command: storeEval, Target: Selenium.prototype.doInnerHTML=function(locator,text){var element=this.browserbot.findElement(locator);if(element===null)return null;element.innerHTML=text}

任何时候你在 Selenium IDE 中创建自定义命令,你也需要重新加载它们,所以我的辅助测试的最后一步是:

Any time you create a custom command in Selenium IDE, you also need to reload them, so the last step of my helper test is:

命令: storeEval,目标: editor.treeView.reloadSeleniumCommands()

Command: storeEval, Target: editor.treeView.reloadSeleniumCommands()

使用此自定义 innerHTML 命令,我可以使用以下方法将内容输入到 contentEditable 区域:

With this custom innerHTML command, I can enter content into contentEditable areas using:

命令:innerHTML,目标: id=message,值:你好!

Command: innerHTML, Target: id=message, Value: Hello!

这篇关于使用 Selenium IDE 在富文本编辑器中输入字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆