Selenium Webdriver——JS处理rich text(富文本框)

126邮件正文邮件的rich text

先让selenium切换到iframe中

driver.switchTo().frame(driver.findElement(By.className("APP-editor-iframe")));

然后执行JS

WebElement editor = driver.findElement(By.tagName("body"));
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
jsExecutor.executeScript("arguments[0].innerHTML = '<h1>Selenium Test </h1>I love Selenium <br> this article Post By Selenium WebDriver<br><h2>Create By Young</h2>'", editor);

最后再切换出iframe

driver.switchTo().defaultContent();

对设置文本框内容进行封装

 /**
* @author hjianhui
* @param locator
* @param text
*/
protected void setRichTextBox(Locator locator, String text) {
WebElement e = findElement(driver, locator);
log.info("type value is: " + text);
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].innerHTML = \"" + text + "\"", e);
}
上一篇:Angularjs2 入门


下一篇:java集群技术(转)