Re: How to access Java Script associated with a button in a page and capture a new window.
Stephane Mikaty <[email protected]>
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Hari,
There are two problems with your test,
1. httpunit won't let you access the button if you don't
put it in a form:
<form>
<input id="launchBtn" type="button"
value="Launch Web Access" onclick="launch(false);">
<form>
2. httpunit does _not_ support setTimeout(), it's just an empty
stub in the code:
$Id: JavaScript.java,v 1.63 2004/12/02 03:43:20 russgold Exp $
463 public void jsFunction_setTimeout() {
464 }
Remove it from your test or use something else than httpunit.
I changed launch() into:
function launch(accessibleMode) {
launchWindow(accessibleMode);
}
Assuming you've fixed both problems, the following code should
do what you want:
public class Test {
public static void main(String[] args) throws Exception {
WebConversation conversation = new WebConversation();
GetMethodWebRequest request = new GetMethodWebRequest("http://...");
WebResponse response = conversation.getResponse(request);
WebForm[] allForms = response.getForms();
WebForm firstForm = allForms[0];
firstForm.getButtons()[0].click();
WebWindow[] allWindows = conversation.getOpenWindows();
WebWindow loginWindow = allWindows[1];
// displays the content of the login window
System.out.println(loginWindow.getCurrentPage().getText());
}
}
Let me know if it helps.
hari prasanna wrote:
> Hi ,
>
> I am starting off workin on with the HTTP Unit. I am trying to simulate
> a flow for login.
>
> There is an Intial page , which contains a Button -Launch. This page
> doesnt have any Forms.
> There is a Java Script associated with the 'Launch' Button ,which on
> click opens up the Login page in a "New Window".
>
> I need to get this simulated and get the Login Page ,to do the Login
> into the App.
> I am stuck in accessing the Java Script to simulate this flow.
> Can someone provide me with ways how to get this done.
>
> Refference : Page Details.
> Button Description on the page:
> <input id="launchBtn" type="button" value="Launch Web Access"
> onclick="launch(false);">
>
> Java Script:
> function launch(accessibleMode) {
> // Provoke the IE popup blocker
> setTimeout(function(){launchWindow(accessibleMode)}, 10);
> }
>
> function launchWindow(accessibleMode) {
> var loginPage = "/app/login.jsp";
> if (accessibleMode) {
> loginPage += "?accessible=true";
> }
> // Center the pop-up window on the screen, and default it to 80% of
> // available screen height and width (but no smaller than 640x480 and
> // no larger than 1024x768):
> var scaleFactor = 0.80;
> var popupWidth = 690; //Math.max(640, Math.min(1024,
> Math.floor(screen.availWidth * scaleFactor)));
> var popupHeight = 500; //Math.max(480, Math.min(768,
> Math.floor(screen.availHeight * scaleFactor)));
> var popupLeft = Math.max(0, Math.round((screen.availWidth -
> popupWidth) / 2));
> var popupTop = Math.max(0, Math.round((screen.availHeight -
> popupHeight) / 2));
> var wName = 'ocsweb_'+hName.replace(/\W/g,"");
>
> try {
> var w = window.open(loginPage, wName, 'width=' + popupWidth +
> ',height=' + popupHeight + ',left=' + popupLeft + ',top=' + popupTop +
> ',resizable=yes,status=yes');
> if (w == null) {
> popupWarn();
> }
> else {
> w.focus();
> }
> }
> catch(e) {
> popupWarn();
> }
> };
>
> Thanks ,
> Hari.
>
> ------------------------------------------------------------------------
> Jiyo cricket on Yahoo! India cricket
> <http://us.rd.yahoo.com/mail/in/mailcricket/*http://in.sports.yahoo.com/cricket/>
> Yahoo! Messenger Mobile
> <http://us.rd.yahoo.com/mail/in/mailmobilemessenger/*http://in.mobile.yahoo.com/new/messenger/>
> Stay in touch with your buddies all the time.
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642