button.click() not working ,ie HTTPUNIT
Hi,
I am bhimi... I am facing problems with "httpunit", I would like to know how to click the "continue" button in Compose Text Message page of www.mail.yahoo.com. with my destination mobile phone number and text message as setting parameters....(I could set these parameters but could not click the "Continue" button).
My user id is "batman2004_2004"
pass- word is "testing"
1. I am logging into mail.yahoo.com with a java testcase using this Httpunit .
2.Next i am entering into the "compose text message page",by clicking "compose text msg" button which lies next to INBOX, COMPOSE buttons with my java program...
3.Next i could enter mobile phone number and text message,but the problem is IT IS NOT CLICKING THE "CONTINUE" BUTTON through my java program...
please let me know ...
Thanks in advance,
Regards,
Bhimi...
My code snippet is as follows....
WebResponse wr = wc.getResponse( "http://mail.yahoo.com");
//get the login form
WebForm form = wr.getFormWithName("login_form");
form.setParameter(".done", "http://mail.yahoo.com");
form.setParameter("login", "batman2004_2004");
form.setParameter("passwd", "testing");
form.submit();
WebResponse wr1 = wc.getResponse( "http://mail.yahoo.com");
WebResponse wr2 = wc.getResponse(ymCompose);
// this is compose SMS page...
WebForm form2 = wr2.getFormWithName("Compose");
form2.setParameter("To","00497953453520");
form2.setParameter("Body", "hi, how r u.");
Button buttons = form4.getButtonWithID("sendtop");
buttons.click();
WebResponse wr4 = wc.getCurrentPage();
I COULD NOT SUCCEED... LATER TRIED THESE STEPS ALSO
WebForm form2 = wr2.getFormWithName("Compose");
form2.setParameter("To","+4979534535203");
form2.setParameter("Body", "hi, how r u.");
SubmitButton submitbutton = form4.getSubmitButton("sendtop");
submitbutton.click();
or also in this way
SubmitButton submitbutton = form4.getSubmitButton("sendtop");
form4.submit(submitbutton);
WebResponse wr4 = wc.getCurrentPage();
PLEASE HELP ME ..............
thanks & regards,
bhimi.
[2254 byte] By [
bhimi2003] at [2007-9-30 17:36:27]

hi,
ya, click is okay... but i dont understand why its not hitting the ""continue "" button. Could u plz help me out.
my snippet is as follows...
WebForm form4 = wr2.getFormWithID("Compose");
form4.setParameter( "To", "0049787878744" );
form4.setParameter( "Body", "badjkgbhajk" );
Button button = form4.getButtonWithID("sendtop");
System.out.println("++++++++" + button.getName());
System.out.println("++++++++" + button.getType());
System.out.println("++++++++" + button.getValue());
if (button != null) {
System.out.println("This is null and it is obvious to get null");
button.click();
form4.submit();
System.out.println("This is null and it is obvious to get null");
}
else {
System.out.println("this is not null+++++++++++++++++");
System.out.println("this is not null +++++++++++++++++");
System.out.println("this is not null++++++++++++++++++");
}
WebResponse wr5 = wc.getCurrentPage();
Hi all, can anyone help me please?
I tried to use this excample for getting the Compose page of mail.Yahoo.com
so
1 - I log in into mail.yahoo.com
2 - after I get the main page,
3 - I get the form containing the "Compose" button.
but when I submit that form, for getting the compose page, I'm getting this exception:
Button ->Check for new mail (Shortcut keys: Control+Shift+C),Check Mail, ID->
Button ->Compose a new message (Shortcut keys: Control+Shift+P),Compose, ID->
Compose button FOUND
Compose button type ->button
-- EXCEPTION
TypeError: getElementsByTagName is not a function. (httpunit; line 8)
at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:597)
at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:557)
at org.mozilla.javascript.NativeGlobal.typeError1(NativeGlobal.java:567)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2178)
at org.mozilla.javascript.InterpretedScript.call(InterpretedScript.java:62)
at org.mozilla.javascript.InterpretedScript.exec(InterpretedScript.java:55)
at org.mozilla.javascript.Context.evaluateReader(Context.java:820)
at org.mozilla.javascript.Context.evaluateString(Context.java:784)
at com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.executeScript(JavaScript.java:132)
at com.meterware.httpunit.scripting.ScriptableDelegate.runScript(ScriptableDelegate.java:65)
at com.meterware.httpunit.parsing.ScriptFilter.getTranslatedScript(ScriptFilter.java:151)
at com.meterware.httpunit.parsing.ScriptFilter.endElement(ScriptFilter.java:131)
at org.cyberneko.html.filters.DefaultFilter.endElement(Unknown Source)
at org.cyberneko.html.filters.NamespaceBinder.endElement(Unknown Source)
at org.cyberneko.html.HTMLTagBalancer.callEndElement(Unknown Source)
at org.cyberneko.html.HTMLTagBalancer.endElement(Unknown Source)
at org.cyberneko.html.HTMLScanner$SpecialScanner.scan(Unknown Source)
at org.cyberneko.html.HTMLScanner.scanDocument(Unknown Source)
at org.cyberneko.html.HTMLConfiguration.parse(Unknown Source)
at org.cyberneko.html.HTMLConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at com.meterware.httpunit.parsing.NekoHTMLParser.parse(NekoHTMLParser.java:41)
at com.meterware.httpunit.HTMLPage.parse(HTMLPage.java:255)
at com.meterware.httpunit.WebResponse.getReceivedPage(WebResponse.java:1126)
at com.meterware.httpunit.WebResponse$Scriptable.load(WebResponse.java:688)
at com.meterware.httpunit.javascript.JavaScript.load(JavaScript.java:89)
at com.meterware.httpunit.javascript.JavaScriptEngineFactory.load(JavaScriptEngineFactory.java:58)
at com.meterware.httpunit.RequestContext.runScripts(RequestContext.java:44)
at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:122)
at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:144)
at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:130)
at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:121)
at com.meterware.httpunit.WebWindow.sendRequest(WebWindow.java:110)
at com.meterware.httpunit.WebRequestSource.submitRequest(WebRequestSource.java:253)
at com.meterware.httpunit.WebRequestSource.submitRequest(WebRequestSource.java:232)
at com.meterware.httpunit.WebForm.submitRequest(WebForm.java:96)
at com.meterware.httpunit.WebForm.doFormSubmit(WebForm.java:107)
at com.meterware.httpunit.WebForm.submit(WebForm.java:69)
at com.meterware.httpunit.WebForm.submit(WebForm.java:58)
at test.TestUploadFile.testUploadFile(TestUploadFile.java:116)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)Exception in MAIN TEST ->com.meterware.httpunit.ScriptException: Script 'd=document;
function setFocus() {
if (d.getElementById) d.getElementById('yschsp').focus();
}
if (d.getElementById) {
oTog=d.getElementById('yschtg');
if (oTog) {
aLnx=oTog.getElementsByTagName('a');
for (var i=0;i<=aLnx.length-1;i++) aLnx.onclick=passP;
}
}
function passP(e) {
e=(e)?e:((window.event)?window.event:"");
if (e) {
var o=(e.target)?((e.target.nodeType==3)?e.target.parentNode:e.target):e.srcElement;
if (o.tagName=='SPAN'||o.tagName=='EM') o=o.parentNode; // Local
if (window.RegExp&&window.encodeURIComponent) {
var sP=encodeURIComponent(d.getElementById('yschsp').value);
sP = encodeURIComponent(sP); //Double encode since this is what ULT does for some reason
if (o.href.indexOf('p=')!=-1) o.href=o.href.replace(/p=[^&$]*/,'p%3D'+sP);
else o.href+='%26p%3D'+sP;}
}
}' failed: TypeError: getElementsByTagName is not a function. (httpunit; line 8)
Last Test comment ->Test failed
Any idea?
thanks a lot
hi bhimi...
i m vipul.
i m facing a problem of login into yahoo mail i m not be able to login in ur code is not work as well for login into yahoo.
i m modified littel ur code check it out and if u have suggastion reply me
nut first run my code on ur system
import com.meterware.servletunit.*;
import com.meterware.httpunit.*;
import junit.framework.*;
import java.net.*;
import java.io.*;
import java.util.*;
import java.lang.String;
import com.meterware.httpunit.WebClient;
class yahoo extends TestCase
{
public static void main(String args[])
{
try{
WebConversation wc = new WebConversation();
WebResponse wr = wc.getResponse( "http://mail.yahoo.com");
//get the login form
WebForm form = wr.getFormWithName("login_form");
form.setParameter(".done", "http://mail.yahoo.com");
form.setParameter("login", "dirty_bv");
form.setParameter("passwd", "hrishihrishi");
System.out.println(form.getParameterValue("passwd"));
form.submit();
assertEquals(wr.getTitle(),"Yahoo! Mail - dirty_bv@yahoo.co.in");
System.out.println(form.getParameterValue("passwd"));
WebResponse wr1 = wc.getResponse( "http://mail.yahoo.com");
System.out.println(wr.getText());
}catch(Exception e){
e.printStackTrace();
}
}
}