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);
    }

 

posted @ 2016-08-04 13:55  hjhsysu  阅读(1226)  评论(0编辑  收藏  举报