2016-03-08 71 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