使用 Selenium IDE 在富文本编辑器中输入字符 [英] Typing characters in rich text editor using 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>
我目前的步骤是:
- 命令:selectFrame,目标:
xpath=//*[contains (@id, 'j_id0:j_id4:j_id6:j_id115:j_id117:textAreaDelegate_Comments__c_frame')]
- 命令:点击,目标:
xpath=//*[contains (@id, 'j_id0:j_id4:j_id6:j_id115:j_id117:textAreaDelegate_Comments__c_rta_body')]
- 命令:焦点,目标:
xpath=//*[contains (@id, 'j_id0:j_id4:j_id6:j_id115:j_id117:textAreaDelegate_Comments__c_rta_body')]
- 命令:sendKeys,目标:
xpath=//*[contains (@id, 'j_id0:j_id4:j_id6:j_id115:j_id117:textAreaDelegate_Comments__c_rta_body')],
值:在富文本编辑器中输入值!!!
- Command: selectFrame, Target:
xpath=//*[contains (@id, 'j_id0:j_id4:j_id6:j_id115:j_id117:textAreaDelegate_Comments__c_frame')]
- Command: click, Target:
xpath=//*[contains (@id, 'j_id0:j_id4:j_id6:j_id115:j_id117:textAreaDelegate_Comments__c_rta_body')]
- Command: focus, Target:
xpath=//*[contains (@id, 'j_id0:j_id4:j_id6:j_id115:j_id117:textAreaDelegate_Comments__c_rta_body')]
- 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屋!