« Return to Thread: Can HtmlUnit support to set the content to an online rich text editor?

Re: Can HtmlUnit support to set the content to an online rich text editor?

by Gary Chen-4 :: Rate this Message:

| View in Thread

Some parts of this message have been removed. Learn more about Nabble's security policy.

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
228 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






------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@...
https://lists.sourceforge.net/lists/listinfo/htmlunit-user

 « Return to Thread: Can HtmlUnit support to set the content to an online rich text editor?