I am using Selenium WebDriver in Eclipse and I am trying to insert text into a tinymce box on a web page. This is the code I am using.
//find tinymce iframe
editorFrame = driver.findElement(By.cssSelector(".col_right iframe"));
//switch to iframe
driver.switchTo().frame(editorFrame);
driver.findElement(By.className("mceContentBody")).sendKeys("YOOOO");
driver.switchTo().defaultContent();
The cursor is blinking inside of the editor, however no text is sent. I have also tried this slight variation without any luck.
//find tinymce iframe
editorFrame = driver.findElement(By.cssSelector(".col_right iframe"));
//switch to iframe
driver.switchTo().frame(editorFrame);
WebElement body = driver.findElement(By.className("mceContentBody"));
body.sendKeys("YOOOO");
driver.switchTo().defaultContent();
Yes, as what Richard says, this is a duplicate of How to input text into tinceMCE editior using selenium/webdriver.
For your specific code, I'd suggest
Try different locator for mceContentBody
, e.g use By.cssSelector(".mceContentBody")
, By.cssSelector("body")
, etc.
Click the body first before sending keys.
driver.findElement(By.tagName("body")).click().sendKeys("YOOOO");
inputWebDriver.switchTo().frame("input-data_ifr");
WebElement element = inputWebDriver.findElement(By.cssSelector("body"));
(JavascriptExecutor)driver.executeScript("arguments[0].innerHTML = '<h1>Set text using innerHTML</h1>'", element);
// no need to switch iframe
(JavascriptExecutor)driver.executeScript("tinyMCE.activeEditor.setContent('<h1>Native API text</h1> TinyMCE')");
Further reading: Test WYSIWYG editors using Selenium WebDriver
Do this (c#)
yourWebDriver.ExecuteScript(string.Format("tinyMCE.getInstanceById('{0}').setContent('{1}');",yourWebElement.GetAttribute("id"), "hello world"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With