Reputation: 1347
I'm trying to select the text of a TinyMCE field with selenium2library keywords (in Plone).
I tried to select the text with mouse events (Mouse Down/Over/Up), Javascript and "Double Click Element" but nothing worked so far. The code below works if I set a debugger and select the text manually:
Go to ${PLONE_URL}/++add++Document
Input Text name=form.widgets.IDublinCore.title My Document
Select frame id=form.widgets.text_ifr
Input text id=content Lorem Ipsum
# Attempt with Javascript
Execute Javascript document.getElementById("content").select()
# Attempt with Double Click
Double Click Element xpath=//body[@id='content']/p[1]
Double Click Element id=content
# Attempt with Mouse Events
Mouse Down xpath=//body[@id='content']/p[contains(text(),'L')]
Mouse Over xpath=//body[@id='content']/p[contains(text(),'orem')]
Mouse Up xpath=//body[@id='content']/p[contains(text(),'Ipsum')]
# When I set a debug statement here and select the text manually the test passes
Unselect Frame
Click Link id=form.widgets.text_link
Wait until page contains element id=mce_31_ifr
Select frame id=mce_31_ifr
Click Link News
...
It would already help if someone could recommend which method is most promising.
Upvotes: 3
Views: 1465
Reputation: 2384
This is just a rehash of a JavaScript question here. For content-editable elements, I think JavaScript is the way to go. The following code selects the entire body of the content-editable portion of the TinyMCE widget.
Open Browser http://www.tinymce.com/ gc
Select Frame id=editMe_ifr
Input Text id=tinymce Lorem Ipsum
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);
Upvotes: 2