• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Java automation to Login to website

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All,

I am in need of writing java application which logs into website.

The website which i want to log in.

i have attached the login screenshot , login html , login javascript and the javacode which i am using.

when i execute the java code , it gives me 200 http response but does not log into the website.

important thing to note is the 'password' in the login page is as part of the javascript and not part of the login form. I have hardcoded to generate this attribute to make it available as part of the post request.

i have also tried loggin using chrome poster ....When i try to post the request via chrome poster to the action url specified in the login form of login.html , i am not able to login to the site.

can anyone guide me as to what am i missing ?
how to set password filed which is available in javascript , is my hard coding in login.java correct?
Is it feasible to automate this login process using java.

any suggestions are greatly welcomed....hoping to have some guidance.

Please let me know if i need to provide further details.




login.java code snippet
------------------------------




Javascript snippet
-------------------






login or index html
---------------------

<HTML><HEAD><TITLE>Citrix Access Gateway</TITLE>
<link rel="SHORTCUT ICON" href="/vpn/images/AccessGateway.ico" type="image/vnd.microsoft.icon">
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META content=noindex,nofollow,noarchive name=robots>
<LINK href="/vpn/images/caxtonstyle.css" type=text/css rel=STYLESHEET>
<script type="text/javascript" src="/vpn/resources.js"></script>
<script type="text/javascript" language="javascript">
var Resources = new ResourceManager("resources/{lang}", "logon");
</script>
<style type="text/css">
body
{
visibility: hidden;
}
</style>
<script language="javascript" type="text/javascript" src="/vpn/nsshare.js"></script>
<script language="JavaScript" type="text/javascript" src="login.js"></script>
<SCRIPT language=JavaScript>
// frame-busting script
setTimeout ("changePage()", 0);
function changePage()
{
if (self.parent != self)
top.location=document.location;
}
function setFocus(obj)
{
if (obj != null) {
obj.focus();
}
}
//-->
</SCRIPT>

<META content="MSHTML 6.00.2900.2802" name=GENERATOR></HEAD>
<BODY id=bodyTag onload="ns_fillName();">
<!-- Copyright 2001-2005 Citrix Systems, Inc. All Rights Reserved -->

<NOSCRIPT>
<BR><BR>
<table style="WIDTH: 100%">
<tr>
<td align="center">
<table class="CTXMSAM_LogonFont">
<tr id="errorMessageRow">
<td class="glowBoxLeft"> </td>
<td class="loginTableMidWidth">
<div id="feedbackArea">
<div id="feedbackStyle" class="feedbackStyleError">
<span id="errorMessageLabel" class="messageStyle">
JavaScript is either disabled in or not supported by the Web browser.
To continue logon, use a Web browser that supports JavaScript or enable JavaScript in your current browser.
</span>
</div>
</div>
</td>
<td class="glowBoxRight"> </td>
</tr>
</table>
</td>
</tr>
</table>

<table style="display:none">
</NOSCRIPT>

<!-- Header -->
<script language="javascript" type="text/javascript">
CreateMainTable();
AddHeaderAndBar();
</script>

<!-- Logon box -->
<tr class="mainPane" >
<td class="carbonBoxBottom" valign="bottom">
<script language="javascript" type="text/javascript">
documentWriteGlowBoxUpper();
</script>
<FORM method="post" action="/cgi/login" name="vpnForm" autocomplete="off" style="margin:0"
onsubmit="clean_name_cookie();">
<table cellspacing="4" cellpadding="0" border="0" width=100%>
<tr>
<td class="CTX_ContentTitleHeader">
<div id="ctl08_loginAgentCdaHeaderText" style="padding-left:15px"><span id="Welcome"></span></div>
</td>
</tr>
<tr>
<td class="CTXMSAM_LogonFont">
<div id="ctl08_loginAgentCdaHeaderText2" style="padding-left:15px"></div>
</td>
</tr>
<tr border=10>
<td class="CTXMSAM_LogonFont" valign="top">
<script language="javascript" type="text/javascript">
documentWriteActionPane();
</script>
<table width=70% id="ctl08_inputTable" class="CTXMSAM_LogonFont" cellspacing="0" cellpadding="4" border="0" style="border-width:0px;border-collapse:collapse;">
<tr><td colspan=3></td></tr>
<tr>
<td align="right" style="padding-right:10px;white-space:nowrap;"><span id="User_name" class="CTXMSAM_LogonFont"></span></td>
<td colspan=2 style="padding-right:8px;"><input id="Enter user name" class="CTXMSAM_ContentFont" style="font-size: 8pt" type="text" title="" name="login" size="30" maxlength="127" onFocus="loginFieldCheck()"style="width:100%;" /></td>
</tr>
<SCRIPT language=JavaScript>ns_showpwd();</SCRIPT>
<tr>
<!-- Disclaimer customization - Add a name to the LogonButton in order to be referenced later -->
<td></td><td></td><td align="right"><span style="display:none"><img src="/vpn/images/LoginButtonRolloverGlow.gif"/></span><input type="submit" id="Log_On" value="" class="CTX_CaxtonButton" onclick="ns_check();" onmouseover="this.className='CTX_CaxtonButton_Hover';" onmouseout="this.className='CTX_CaxtonButton';" name="LogonButton" disabled="true"/></td>
</tr>
<!-- Disclaimer customization -->
<tr><td colspan=3 align="center" style="font-size: 12pt" type="text" ><input type="checkbox" name="chk1_button" onClick="enableLogonButton(this);"/>  I Accept</td></tr>
<tr><td colspan=3 align="left" style="font-size: 8pt" type="text" >  By checking <b>"I Accept"</b> above you agree to the following terms and conditions:</td></tr>
<tr><td colspan=3 align="left" style="font-size: 8pt" type="text" >  Use of this system evidences an express consent to such monitoring and agreement that if such monitoring reveals evidence of possible abuse or criminal activity, system personnel may provide the results of such monitoring to appropriate officials.</td></tr>
</table>
<!-- End of Disclaimer customization-->

</div>
</td>
</tr>
</table>
</FORM>
<script language="javascript" type="text/javascript">
documentWriteGlowBoxLower();
</script>
</td>
</tr>

<!-- Error message box -->
<tr>
<td align="center">
<table class="CTXMSAM_LogonFont">
<tr id="errorMessageRow">
<td class="glowBoxLeft"> </td>

<td class="loginTableMidWidth">

<script language='javascript'>ns_disperrmsg();</script>

</td>

<td class="glowBoxRight"> </td>
</tr>
</table>
</td>
</tr>

<!-- Footer -->
<script language="javascript" type="text/javascript">
AddFooter();
</script>
</table>

<DIV id=scriptArea></DIV>
<script type="text/javascript" language="javascript">
Resources.Load();
</script>
</BODY>
</HTML>

Login_SCreen.png
[Thumbnail for Login_SCreen.png]
login screen
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If this was my problem I'd use the HtmlUnit library for this. Much easier than coding it all yourself.
 
Nikhil Velayudham
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Marshall , I will look up some examples to see how to get it done.

If you happen to have any code samples please share.

Thanks
 
Nikhil Velayudham
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks,

Looking for more suggestions , if you have any please share.

thanks!
 
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My suggestion is to follow Ulf's suggestion.
 
Nikhil Velayudham
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Bear...i am in the process of trying it out.

 
Marshal
Posts: 80867
505
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I added code tags to your post. Always use them (you can even change them to format JS). Doesn't it look better I had to break some of the long lines. I am not sure how to format the HTML, however.
 
Nikhil Velayudham
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aim;

Login to the citrix portal shown in the above screenshot successfully.

Problem:

Password field is not available in the login form [index.html].

Javascript function[ns_showpwd()] is being used in the index.html at the place of password field.

This javascript function has the html code for generating the password field [code is attached in the begining of the thread].

When i look at the view source of index.html , the html content of ns_showpwd() is not loaded in the page, page is designed that way .

Error:

With my current htmlunit program i am getting below error as mycode is not finding the passwd field as it is not available in [index.html]

Exception in thread "main" com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[input] attributeName=[name] attributeValue=[passwd]
at com.gargoylesoftware.htmlunit.html.HtmlForm.getInputByName(HtmlForm.java:412)
at com.auto.login.JiraLogin.logIn(JiraLogin.java:74)
at com.auto.login.JiraLogin.main(JiraLogin.java:52)

Question

How do i read the password field which is in the javascript using htmlunit , so that i can click and log in to the portal.

Attaching my current htmlunit code for reference.


Please help guide me as to how we can retrieve passwd field .
 
Nikhil Velayudham
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
htmlunit java code




 
Nikhil Velayudham
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All,

Any pointers or help on this topic........need inputs to be able to complete this task .


Regards,
Nikhil
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, I thought the code you posted yesterday was the solution, since there wasn't any question on it. What does or does it not do? What's still missing?
 
Nikhil Velayudham
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here are the questions..


Aim;

Login to the citrix portal shown in the above screenshot successfully.

Problem:

Password field is not available in the login form [index.html].

Javascript function[ns_showpwd()] is being used in the index.html at the place of password field.

This javascript function has the html code for generating the password field [code is attached in the begining of the thread].

When i look at the view source of index.html , the html content of ns_showpwd() is not loaded in the page, page is designed that way .

Error:

With my current htmlunit program i am getting below error as mycode is not finding the passwd field as it is not available in [index.html]

Exception in thread "main" com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[input] attributeName=[name] attributeValue=[passwd]
at com.gargoylesoftware.htmlunit.html.HtmlForm.getInputByName(HtmlForm.java:412)
at com.auto.login.JiraLogin.logIn(JiraLogin.java:74)
at com.auto.login.JiraLogin.main(JiraLogin.java:52)

Question

How do i read the password field which is in the javascript using htmlunit , so that i can click and log in to the portal.

Attaching my current htmlunit code for reference.


Please help guide me as to how we can retrieve passwd field .
reply
    Bookmark Topic Watch Topic
  • New Topic