[prev in list] [next in list] [prev in thread] [next in thread]
List: htmlunit-user
Subject: Re: [Htmlunit-user] Problem with struts text fields and form
From: Daniel Gredler <djgredler () gmail ! com>
Date: 2009-08-26 14:33:15
Message-ID: ffe1e27a0908260733j47efc5a6ne4216ef347bb6c58 () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Hi Ahmed,
The s:form stuff is probably a JSP tag which gets converted info a form tag
by the app server before being fed to the browser.
Take care,
Daniel
On Wed, Aug 26, 2009 at 7:21 AM, Ahmed Ashour <asashour@yahoo.com> wrote:
> Hi Parag,
>
> Arguable, page.getFormByName() should not retrieve forms defined as
> <xxx:form>, because the below HTML example is evaluated to 'undefined' in
> real IE/FF, but if you make the form <form>, then you will have a value.
> (HtmlUnit evaluates the example to an object, which is a bug :)
>
> For your case, you can try something like:
>
> HtmlForm form = page.getFirstByXPath(".//*[@name='fmLogin']");
> HtmlUnknownElement input =
> form.getFirstByXPath(".//*[@name='hdUserID']");
> input.setAttribute("value", "something");
>
> I am still not sure if <s:form> should be evaluated to HtmlForm or
> HtmlUnknownElement, this needs further investigations.
>
>
> <head>
> <script>
> function test() {
> alert(document.forms.fmLogin);
> }
> </script>
> </head>
> <body onload='test()'>
> <s:form name="fmLogin" action="doLogin" method="POST">
> <s:hidden name="hdUserID"/>
> <s:hidden name="hdPassword"/>
> </s:form>
> </body>
> Yours,
> Ahmed
> ----
> Blog: http://asashour.blogspot.com
> ------------------------------
> *From:* Parag Ghodaskar <parag..ghodaskar@gmail.com>
> *To:* htmlunit-user@lists.sourceforge.net
> *Sent:* Wednesday, August 26, 2009 12:49:41 PM
> *Subject:* Re: [Htmlunit-user] Problem with struts text fields and form
>
> import junit.framework.*;
> import com.gargoylesoftware.htmlunit.*;
> import com.gargoylesoftware.htmlunit.html.*;
> import com.gargoylesoftware.htmlunit.html.xpath.*;
>
>
> public class HtmlUnitTest extends TestCase {
> public void testHomePage() throws Exception {
> final WebClient webClient = new WebClient();
> final HtmlPage page = webClient.getPage("
> http://192.168.2.201:8080/mes-hpl-web21aug/");
> assertEquals("HtmlUnit - Welcome to HtmlUnit",
> page.getTitleText());
> final HtmlForm form = page.getFormByName("fmLogin");
> final HtmlSubmitInput button = form.getInputByName("sub");
> final HtmlTextInput loginField = form.getInputByName("hdUserID");
> final HtmlTextInput passField = form.getInputByName("hdPassword");
> // Change the value of the text field
> loginField.setValueAttribute("Administrator");
> passField.setValueAttribute("admin@123");
> // Now submit the form by clicking the button and get back the
> second page.
> final HtmlPage page2 = button.click();
>
> assertEquals("Result",page2.getTitleText());
>
> }
>
> }
>
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Htmlunit-user mailing list
> Htmlunit-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/htmlunit-user
>
>
--
Daniel Gredler
http://daniel.gredler.net/
[Attachment #5 (text/html)]
Hi Ahmed,<br><br>The s:form stuff is probably a JSP tag which gets converted info a \
form tag by the app server before being fed to the browser.<br><br>Take \
care,<br><br>Daniel<br><br><br><div class="gmail_quote">On Wed, Aug 26, 2009 at 7:21 \
AM, Ahmed Ashour <span dir="ltr"><<a \
href="mailto:asashour@yahoo.com">asashour@yahoo.com</a>></span> wrote:<br> \
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); \
margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div style="font-family: times \
new roman,new york,times,serif; font-size: 12pt;"><div></div>
<div>Hi Parag,</div>
<div> </div>
<div>Arguable, page.getFormByName() should not retrieve forms defined as \
<xxx:form>, because the below HTML example is evaluated to 'undefined' \
in real IE/FF, but if you make the form <form>, then you will have a value. \
(HtmlUnit evaluates the example to an object, which is a bug :)</div>
<div> </div>
<div>For your case, you can try something like:</div>
<div> </div>
<div> HtmlForm form = \
page.getFirstByXPath(".//*[@name='fmLogin']");<br> \
HtmlUnknownElement input = \
form.getFirstByXPath(".//*[@name='hdUserID']");<br> \
input.setAttribute("value", "something");<br> </div>
<div> </div>
<div>I am still not sure if <s:form> should be evaluated to HtmlForm or \
HtmlUnknownElement, this needs further investigations.</div> <div> </div>
<div> </div>
<div><head><br> <script><br> function test() {<br> \
alert(document.forms.fmLogin);<br> }<br> \
</script><br></head><br><body onload='test()'><div \
class="im"><br><s:form name="fmLogin" action="doLogin" \
method="POST"><br> <s:hidden \
name="hdUserID"/><br><s:hidden \
name="hdPassword"/><br></div></s:form><br></body><br></div><div \
class="im"> <div>Yours,</div>
<div>Ahmed</div>----<br>Blog: <a href="http://asashour.blogspot.com" \
target="_blank">http://asashour.blogspot.com</a> </div><div><font face="Tahoma" \
size="2"><div class="im"> <hr size="1">
<b><span style="font-weight: bold;">From:</span></b> Parag Ghodaskar <<a \
href="mailto:parag..ghodaskar@gmail.com" \
target="_blank">parag..ghodaskar@gmail.com</a>><br><b><span style="font-weight: \
bold;">To:</span></b> <a href="mailto:htmlunit-user@lists.sourceforge.net" \
target="_blank">htmlunit-user@lists.sourceforge.net</a><br> </div><b><span \
style="font-weight: bold;">Sent:</span></b> Wednesday, August 26, 2009 12:49:41 \
PM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [Htmlunit-user] \
Problem with struts text fields and form<br> </font><div><div></div><div \
class="h5"><br>import junit.framework.*;<br>import \
com.gargoylesoftware.htmlunit.*;<br>import \
com.gargoylesoftware.htmlunit.html.*;<br>import \
com.gargoylesoftware.htmlunit.html.xpath.*;<br><br> <br>public class HtmlUnitTest \
extends TestCase {<br> public void testHomePage() throws Exception {<br> \
final WebClient webClient = new WebClient();<br> final HtmlPage page = \
webClient.getPage("<a href="http://192.168.2.201:8080/mes-hpl-web21aug/" \
target="_blank">http://192.168.2.201:8080/mes-hpl-web21aug/</a>");<br>
assertEquals("HtmlUnit - Welcome to HtmlUnit", page.getTitleText());<br> \
final HtmlForm form = page.getFormByName("fmLogin");<br> final \
HtmlSubmitInput button = form.getInputByName("sub");<br> final \
HtmlTextInput loginField = form.getInputByName("hdUserID");<br> \
final HtmlTextInput passField = form.getInputByName("hdPassword");<br> \
// Change the value of the text field<br> \
loginField.setValueAttribute("Administrator");<br> \
passField.setValueAttribute("admin@123");<br> // Now submit the form \
by clicking the button and get back the second page.<br> final HtmlPage page2 \
= button.click();<br>
<br> assertEquals("Result",page2.getTitleText());<br> <br> \
}<br><br>}<br></div></div></div></div><br>
</div><br>------------------------------------------------------------------------------<br>
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day<br>
trial. Simplify your report design, integration and deployment - and focus on<br>
what you do best, core application coding. Discover what's new with<br>
Crystal Reports now. <a href="http://p.sf.net/sfu/bobj-july" \
target="_blank">http://p.sf.net/sfu/bobj-july</a><br>_______________________________________________<br>
Htmlunit-user mailing list<br>
<a href="mailto:Htmlunit-user@lists.sourceforge.net">Htmlunit-user@lists.sourceforge.net</a><br>
<a href="https://lists.sourceforge.net/lists/listinfo/htmlunit-user" \
target="_blank">https://lists.sourceforge.net/lists/listinfo/htmlunit-user</a><br> \
<br></blockquote></div><br><br clear="all"><br>-- <br>Daniel Gredler<br><a \
href="http://daniel.gredler.net/">http://daniel.gredler.net/</a><br>
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Htmlunit-user mailing list
Htmlunit-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/htmlunit-user
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic