本文介绍了selenium webdriver如何在iframe wysiwyg文本区域输入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在iframe wysiwyg文本区域中输入文本
how to get text entered in iframe wysiwyg text area
// Enter text for Message field
ContactUs_Page.txt_keyInMessage().sendKeys(ColMessage);
ContactUs_Page.java
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 code
iframe html code
<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>
例如。在这里输入的文字是
eg. text entered here is
你好,请在收到此消息后与我联系
"hello, pls contact me once you received this message"
如果在正常文本框中,它可以使用 getAttribute(value)
if in normal textbox, it can use getAttribute("value")
但在iframe所见即所得的文本区域中,它没有 value
type
but in iframe wysiwyg text area, it don’t have value
type
请告知,谢谢。
推荐答案
看起来它只是 body
元素中的 text
元素code> iframe :
Looks like it is just the text
of the body
element inside an iframe
:
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());
这篇关于selenium webdriver如何在iframe wysiwyg文本区域输入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!