【问题标题】:How to input values in tinymce text editor for robotframework selenium2library in iframe?如何在tinymce文本编辑器中为iframe中的robotframework selenium2library输入值?
【发布时间】:2016-06-22 12:00:48
【问题描述】:

对于放置在框架内的文本编辑器主体,我无法使用“输入文本”关键字输入文本.. 可以使用按键关键字来完成。

Select Frame    editor_ifr          
sleep   5           
${1}    Get Text    //*[@id='tinymce']/p        
Press Key   //*[@id='tinymce']/p    abcde       
Comment Run Keyword And Ignore Error    Input Text  //*[@id='tinymce']/p    Test
Comment ${tst}  Run Keyword And Ignore Error    Execute Javascript  tinyMCE.activeEditor.setContent('Your text')
Comment Run Keyword And Ignore Error    Input Text  + "</p>'")  Test
${1}    Get Text    //*[@id='tinymce']/p        

【问题讨论】:

  • 您的问题不清楚。第一句话说您可以使用press key 关键字来做到这一点。如果是这样,您的问题是什么?
  • 不知道 tinymce,但 Odoo 有一个所见即所得的编辑器,它是一个模拟文本字段的 iframe。当我在其中输入文本时,我可以看到检查器中生成的 HTML 代码。这是你拥有的那种领域吗?无论如何,我已经能够使用以下方法在其中输入文本: Press Key xpath=//div[@class='oe_form_field oe_form_field_html']//iframe Hello World!

标签: python selenium robotframework


【解决方案1】:

我用两种方式输入文本,通过 javascript 用于 phantomjs 和 selenium Input Text 关键字。

# Select TinyMCE iframe for the instructions field.
Select Frame    id=tinymceIframe
sleep   5

# Input Text only works with browsers for tinymce. It's not working for phantomjs because the field in
# TinyMCE is a contenteditable element and not an input or textarea field.
Input Text    id=tinymce    This is works

# To side step the contenteditable field, for phantomjs, the content of the tinyMCE iframe body will be
# changed via JavaScript, if the browser is set to phantomjs
Run keyword if   '${BROWSER}' == 'phantomjs'  Execute Javascript   document.getElementById("tinymce").innerHTML='This is works';

# Ensure tinymce reflects this change in the text editor
Execute Javascript    function selectElementContents(el) {var range = document.createRange(); range.selectNodeContents(el); var sel = window.getSelection(); sel.removeAllRanges(); sel.addRange(range);} var el = document.getElementById("tinymce"); selectElementContents(el);

# Exit the TinyMCE iframe
Unselect Frame

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-08
    • 2021-10-23
    • 1970-01-01
    • 1970-01-01
    • 2012-11-03
    相关资源
    最近更新 更多