【问题标题】:selenium webdriver how to get text entered in iframe wysiwyg text areaselenium webdriver如何获取在iframe所见即所得文本区域中输入的文本
【发布时间】:2015-03-04 02:22:09
【问题描述】:

如何在 iframe 所见即所得文本区域中输入文本

// Enter text for Message field
ContactUs_Page.txt_keyInMessage().sendKeys(ColMessage);

ContactUs_Page.java

public static WebElement txt_keyInMessage() throws Exception{
    try{     
        WebElement iframeMsg= driver.findElement(By.xpath("//*[contains(@class, 'wysiwyg_frame')]"));        
        driver.switchTo().frame(iframeMsg);     
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);         
        element = driver.findElement(By.cssSelector("body"));    
    }catch (Exception e){
        throw(e);
    }
    return element;
}

iframe html 代码

<iframe class="wysiwyg_frame" frameborder="0" src="" style="width: 100%; height: 100%;" title="Rich Text Editor, contact_remarks" aria-describedby="cke_30" tabindex="0" allowtransparency="true">
    <!DOCTYPE html>
    <html lang="en" dir="ltr">
        <head>
        <body class="cke_editable cke_editable_themed cke_contents_ltr cke_show_borders" contenteditable="true" spellcheck="false">
            <p>
                hello, pls contact me once you received this message
                <br>
            </p>
        </body>
        </html>
</iframe>

例如。此处输入的文字是

“您好,收到此消息后请与我联系”

如果是普通文本框,可以使用getAttribute(“value”)

但在 iframe 所见即所得的文本区域中,它没有 value 类型

请指教,谢谢。

【问题讨论】:

    标签: java selenium iframe selenium-webdriver wysiwyg


    【解决方案1】:

    看起来它只是iframebody 元素的text

    WebElement iframeMsg = driver.findElement(By.xpath("//*[contains(@class, 'wysiwyg_frame')]"));        
    driver.switchTo().frame(iframeMsg);
    
    WebElement body = driver.findElement(By.cssSelector("body"));
    System.out.println(body.getText());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-16
      • 2010-09-22
      • 2017-05-30
      相关资源
      最近更新 更多