« Return to Thread: Can HtmlUnit support to set the content to an online rich text editor?
Hi Ahmed,
Thanks a lot.
- Using .type() the characters
I use the following method, but it doesn’t work.
//Content iframe.
HtmlInlineFrame iFrame = (HtmlInlineFrame) currentPage.getElementByName("content");
//System.out.println(iFrame.asXml());
//currentPage = iFrame.click();
iFrame.focus();
iFrame.type("13911111111");
- Setting the DOM values directly.
How to do it?
I had use the code to run javascript snippet.
ScriptResult result = currentPage.executeJavaScript(javascript_snippet);
currentPage = (HtmlPage) result.getNewPage();
The javascript snippet is:
function getFrameNode(a)
{
return document.frames?document.frames[a]:document.getElementById(a).contentWindow;
}
function execComm(d,b,a)
{
var richTxtName="content";
var g=getFrameNode(richTxtName);
g.focus();
if(d=="insertHtml")
{
if(document.all)
{
var c=g.document.selection.createRange();
c.pasteHTML(a);
c.collapse(false);
c.select();
}
else
{
g.document.execCommand(d,b,a);
}
}
else
{
try
{
g.document.execCommand(d,b,a);
}catch(f)
{}
}
g.focus()
}
function addText2()
{
var richTxtName="content";
getFrameNode(richTxtName).document.designMode="on";
//getFrameNode(rteName).focus();
execComm("insertHtml",false,"<b>I am here.</b>");
}
addText2();
but it doesn’t work either.
Best Regards,
Gary
From: Ahmed Ashour [mailto:asashour@...]
Sent: 2012年2月28日 18:17
To: htmlunit-user@...
Subject: Re: [Htmlunit-user] Can HtmlUnit support to set the content to an online rich text editor?
Hi Gary,
You could try:
- Using .type() the characters
- Setting the DOM values directly.
Yours,
Ahmed
From: Gary Chen <gchen@...>
To: "htmlunit-user@..." <htmlunit-user@...>
Sent: Tuesday, February 28, 2012 12:14 PM
Subject: [Htmlunit-user] Can HtmlUnit support to set the content to an online rich text editor?
I am using HtmlUnit to test a web application. It uses an online rich text editor to collect the user input. (The iframe is used without src attribute ). I have to simulate the user input, but I find I have no way to set the content into this iframe.
Can HtmlUnit support this functionality? I googled the web heavily, but found no clear answer.
Best Regards,
Gary Chen
« Return to Thread: Can HtmlUnit support to set the content to an online rich text editor?
| Free embeddable forum powered by Nabble | Forum Help |