I am looking to update the content of an iframe with new material using Selenium WebDriver.
Note: I have attempted the following method:
driver.swithTo().frame(frame_webelement);
driver.findElement(By.xxx).sendKeys("Mycontent");
While I was able to clear the contents of the body within the iframe (using MyWebElement.clear()), I encountered difficulty in sending new content via MywebElement.sendKeys().
Subsequently, I tried a JavaScript solution:
if (driver instanceof JavascriptExecutor) {
((JavascriptExecutor) driver).executeScript("document.getElementsByClassName('iframeClass')[0].contentDocument.body.innerHTML='hello_text'");
}
Upon execution, I received an exception stating "document.getElementsByClassName('iframeClass')[0]" is undefined. Interestingly, the same script worked correctly on FireBug.