2016-03-08 68 views
2

我无法使用'输入文本'关键字输入文本,为放置在框架内的texteditor身体..能够用按键关键字来做到这一点。如何在iframe中的robotframework selenium2library的tinymce文本编辑器中输入值?

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   
+0

你的问题还不清楚。第一句话说你可以用'press key'关键字来做到这一点。如果是这样,你的问题是什么? –

+0

我也有这样的问题!任何人都可以帮我找到一个好的解决方案吗? –

+0

不知道tinymce,但Odoo有一个WYSIWYG编辑器,它是一个模拟文本字段的iframe。我可以看到检查器中生成的HTML代码,因为我在其中键入文本。这是你拥有的领域吗?无论如何,我已经能够使用这个输入文本:按键xpath = // div [@ class ='oe_form_field oe_form_field_html'] // iframe Hello World! – Jerther

回答

0

我输入的文本两种方式,通过JavaScript来phantomjs和硒输入文本关键字。

# 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