Reputation: 21661
I'm trying to add text to TinyMCE using SELENIUM. I've been able to add text using this code:
$('iframe').last().contents().find('body').text('401c484b-68e4-4bf2-a13d-2a564acddc04');
The TinyMCE editor is displaying the GUID. However, when Selenium click the submit button, I'm getting an error: Please, enter a text.
.
I've noticed that, while Selenium is running, I just need to click (manually) on the TinyMCE then, when the update button is clicked, the text is returned.
So how do I click the TinyMCE using javascript or jQuery?
Upvotes: 0
Views: 693
Reputation: 21661
My answer came from this post @SiKing pointed me to.
public void EnterTextInTinyMCE(int n, string noteText, string escapeElementCss)
{
driver.SwitchTo().Frame(n - 1);
IWebElement body = driver.FindElement(By.XPath("//body"));
body.Click();
Wait(3);
IJavaScriptExecutor jse = driver as IJavaScriptExecutor;
jse.ExecuteScript("arguments[0].innerHTML = '" + noteText + "'", body);
driver.SwitchTo().DefaultContent();
Wait(3);
ClickLinkByFullCSS(escapeElementCss); //--- I ADDED THIS LINE TO FORCE
//--- THE IFRAME ELEMENT TO LOSE FOCUS
}
ClickLinkByFullCSS();
is just a method that I defined in the base class and escapeElementCss
is just an element outside the iframe
. I chose the title bar because it's just a div that doesn't have any button, to avoid clicking on an element that might produce an event.
In fact, switching back to DefaultContent is pulling the focus away from the editor. So I just client to an element outside the editor. That force the editor to lose focus and the update was successful.
Upvotes: 1