Windows Scripting
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsSystem AdministrationWindows Scripting

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old July 20th, 2007, 08:07 AM
Neodark Neodark is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 31 Neodark User rank is Corporal (100 - 500 Reputation Level)Neodark User rank is Corporal (100 - 500 Reputation Level)Neodark User rank is Corporal (100 - 500 Reputation Level)Neodark User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 8 h 26 m 58 sec
Reputation Power: 4
WSH - How to target a button with ebeded code?

Hey guys,

Need some help, I've been having a hard time targeting, then clicking a form button to submit a form with my script. The button is in a frame, and it also has onclick code attached to it like so:

Code:
<input value="Refresh" name="go" onclick="document.skipCheck=true; setTimeout('document.forms[\'StampForm\'].submit();',1);" type="button">


The script must do the following:

1- Open IE
2- enter login and password data
3- submit the form.
4- Once that's completed wait for IE to load the new page
5- finally click another form button.
6- stop

1- 4 is not a problem, but the 2nd button is not working. No matter what I try, here's the code I have:

Code:
Option Explicit

Dim objIE : Set objIE = CreateObject("InternetExplorer.Application")

objIE.Navigate "about:blank"
objIE.Visible = True

 WScript.Sleep 500

objIE.Navigate "www.site.com"

Do Until objIE.ReadyState = 4
  WScript.Sleep 500
Loop 

objIE.Document.All.logonForm.username.value = "login name"
objIE.Document.All.logonForm.password.value = "123456"
objIE.Document.All.logonForm.submit.click()

With objIE
  While .Busy
    'Do Nothing
  Wend
  While .document.Readystate <> "complete"
    'AgaIn Do Nothing
  Wend
End With
'My code works until it gets to the line below
'It errors with object does not support this etc
objIE.Document.All.Forms("StampForm").Item("go").Click()

Stop


I cannot change the code of the form itself, and I'm still new to WSH and VBS.

I tried these as well with no result:

1. objIE.document.all.Item("go").Click
2. objIE.document.forms(StampForm).Submit
3. objIE.document.forms(StampForm).Submit.click

Please help

Reply With Quote
  #2  
Old July 20th, 2007, 08:49 AM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Novice (500 - 999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 675 Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Days 18 h 35 m 6 sec
Reputation Power: 308
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo
MySpace
Here's the proper syntax to submit that form.

objIE.document.StampForm.Submit

That lets you submit it without having to "click" the button.

vb Code:
Original - vb Code
  1. Option Explicit
  2.  
  3. Dim objIE : Set objIE = CreateObject("InternetExplorer.Application")
  4.  
  5. objIE.Navigate "about:blank"
  6. objIE.Visible = True
  7.  
  8.  WScript.Sleep 500
  9.  
  10. objIE.Navigate "www.site.com"
  11.  
  12. Do Until objIE.ReadyState = 4
  13.   WScript.Sleep 500
  14. Loop
  15.  
  16. objIE.Document.All.logonForm.username.value = "login name"
  17. objIE.Document.All.logonForm.password.value = "123456"
  18. objIE.Document.All.logonForm.submit.click()
  19.  
  20. With objIE
  21.   While .Busy
  22.     'Do Nothing
  23.   Wend
  24.   While .document.Readystate <> "complete"
  25.     'AgaIn Do Nothing
  26.   Wend
  27. End With
  28.  
  29. objIE.Document.Form.StampForm.Submit
  30.  
  31. Stop


You should post your html for the form to make sure it's correct as well.
__________________
Click the image if at any point you don't like my decision.

Scripting problems? Windows questions? Ask the Windows Guru!


Last edited by Nilpo : July 20th, 2007 at 08:52 AM.

Reply With Quote
  #3  
Old July 20th, 2007, 10:33 AM
Neodark Neodark is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 31 Neodark User rank is Corporal (100 - 500 Reputation Level)Neodark User rank is Corporal (100 - 500 Reputation Level)Neodark User rank is Corporal (100 - 500 Reputation Level)Neodark User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 8 h 26 m 58 sec
Reputation Power: 4
Thanks for the quick reply.

I've previously tried objIE.Document.Form.StampForm.Submit however it does not work, I assume it's because the submit button on this form has onlick associated with it, and the form is within a frame.. Thus why I was trying emulate a click on the button of course Im a noob and could be completely off

changes to the form itself are out of my hands, but here's the code on that form

Code:
<form name="StampForm" action="link.jsp" method="post">
   <table align="center" border="0" cellpadding="2" cellspacing="0" width="760">
	  <tbody><tr align="left" valign="middle"> 
		 <td class="RegularText" colspan="3" height="44" width="760">&nbsp;</td>
	  </tr>
	  
		  <tr align="left" valign="middle"> 
			 <td class="GroupLabel" colcite="2" align="right" height="36" width="126">&nbsp;</td>

			 <td class="GroupLabel" height="36" width="58">Transfer&nbsp; </td>
			 <td height="36" width="542"> 
				<input name="transfer" size="40" value="" onchange="document.hasChanged = true;">
				<a href="javascript:void(0);" onclick="skipCheck = true; setTimeout('openSearchWin(document.forms[\'StampForm\'].transfer, false, true, false);',1);">
					<img src="link/select_btn.gif" alt="Select account entries for transfer" align="absmiddle" border="0"></a>
			 </td>
		  </tr>
	  
		<tr align="left" valign="middle"> 
			<td class="RegularText" colspan="3" height="32" width="760">&nbsp;</td>

		  </tr>
	  
	  <tr align="left" valign="middle"> 
		 <td class="RegularText" height="18" width="126">&nbsp;</td>
		 <td height="18" width="58">&nbsp;</td>
		 <td height="18" width="542">&nbsp;</td>
		 <td height="18" width="18">&nbsp;</td>
	  </tr>
   </tbody></table>
<table align="center" border="0" cellpadding="0" cellspacing="0" height="42" width="760">
  <tbody><tr width="100%" valign="top"> 
	<td class="Label" align="right" height="51" width="333">&nbsp;</td>

	<td align="center" height="51" width="89"><input value="Refresh" name="Go" onclick="document.skipCheck=true; setTimeout('document.forms[\'StampForm\'].submit();',1);" type="button"></td>
	<td class="LoginName" align="left" height="51" width="338">&nbsp;</td>
  </tr>
</tbody></table>



</form>

Reply With Quote
  #4  
Old July 20th, 2007, 10:58 AM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Novice (500 - 999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 675 Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Days 18 h 35 m 6 sec
Reputation Power: 308
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo
MySpace
Oh, sorry...wasn't thinking about the frame. Try this:

objIE.FrameName.Document.FormName.Submit

Reply With Quote
  #5  
Old July 20th, 2007, 12:08 PM
Neodark Neodark is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 31 Neodark User rank is Corporal (100 - 500 Reputation Level)Neodark User rank is Corporal (100 - 500 Reputation Level)Neodark User rank is Corporal (100 - 500 Reputation Level)Neodark User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 8 h 26 m 58 sec
Reputation Power: 4
Same error, object does not support this property or method.

Code:
<frame src="link.jsp_files/body.htm" frameborder="0" name="homebody" marginwidth="0" marginheight="0" scrolling="yes">


The name of the frame is "homebody"

Reply With Quote
  #6  
Old July 20th, 2007, 12:19 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Novice (500 - 999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 675 Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Days 18 h 35 m 6 sec
Reputation Power: 308
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo
MySpace
Quote:
Originally Posted by Neodark
Same error, object does not support this property or method.

Code:
<frame src="link.jsp_files/body.htm" frameborder="0" name="homebody" marginwidth="0" marginheight="0" scrolling="yes">


The name of the frame is "homebody"
Please provide the text of the line number indicated by the error.

Reply With Quote
  #7  
Old July 20th, 2007, 02:03 PM
Neodark Neodark is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 31 Neodark User rank is Corporal (100 - 500 Reputation Level)Neodark User rank is Corporal (100 - 500 Reputation Level)Neodark User rank is Corporal (100 - 500 Reputation Level)Neodark User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 8 h 26 m 58 sec
Reputation Power: 4
Line 29
Char 1
Objet doesn't support this propery or method: homebody
800A01B6

vb Code:
Original - vb Code
  1. Option Explicit
  2.  
  3. Dim objIE : Set objIE = CreateObject("InternetExplorer.Application")
  4.  
  5. objIE.Navigate "about<b></b>:blank"
  6. objIE.Visible = True
  7.  
  8.  WScript.Sleep 500
  9.  
  10. objIE.Navigate "www.site.com"
  11.  
  12. Do Until objIE.ReadyState = 4
  13.   WScript.Sleep 500
  14. Loop
  15.  
  16. objIE.Document.All.logonForm.username.value = "login name"
  17. objIE.Document.All.logonForm.password.value = "123456"
  18. objIE.Document.All.logonForm.submit.click()
  19.  
  20. With objIE
  21.   While .Busy
  22.     'Do Nothing
  23.   Wend
  24.   While .document.Readystate <> "complete"
  25.     'AgaIn Do Nothing
  26.   Wend
  27. End With
  28.  
  29. objIE.homebody.Document.StampForm.Submit


LINE 29: objIE.homebody.Document.StampForm.Submit

Thanks for all your help, I really appreciate it.

Reply With Quote
  #8  
Old November 29th, 2007, 10:08 PM
AndreCarnevale AndreCarnevale is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 1 AndreCarnevale User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 27 m 51 sec
Reputation Power: 0
Actually i have the same problem, but the diference is that my "submit button" is an image, and when you click it, it "encrypt" the Post Data.

How can i solve this problem ?

I will post my VBA SCRIPT and the HTML CODE.

VBA SCRIPT
Code:
  Dim objIE As Object
  Set objIE = CreateObject("InternetExplorer.application")
    
  With objIE
    .Visible = True
    .WindowState = xlMaximized
    .Navigate "https://www.mysite.com/login/login.jsp"
    
    Do While .Busy = True
      DoEvents
    Loop
    Do While .ReadyState <> 4
      DoEvents
    Loop
       
    .Document.enviar.username.Value = "andre"
    .Document.enviar.senha_1.Value = "andre#1"
  End With



HTML CODE
Code:
<form name=enviar method="post" action="prc_login.jsp" onSubmit="return ValidaCampos();">
    <table border="0">
    <tr>
        <td valign="top"><img src="../img/login/usuario.gif" alt="Entre com o usuário de acesso." width="51" height="18" vspace="3" align="absmiddle"></td>
        <td rowspan="2"><img src="../img/login/linha.gif" width="14" height="41"></td>
        <td width="40" valign="top"><input name=username type=text class="EditNormal" size=15 onFocus="return (FocusNome())" ><br><br>
    </td>
    </tr>
    <tr>
         <td><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong><img src="../img/login/senha.gif" width="41" height="18"></strong></font></td>
          <td width="800" valign="baseline"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong>
          <input name=senha_1 type=password class="Edit" id="senha_1" size=15>
          <input name=senha type=hidden id="senha">
          <input name=senha2 type=hidden id="senha2">
          <img src="../img/login/tracejado.gif" width="40" height="2" align="absmiddle">

          <input NAME="Entrar" type="image" id="Entrar"  onClick="if(ValidaCampos()){document.forms[0].submit();} return false;" src="../img/login/ok.gif" width="18" height="9" border="0" >
                 </strong></font></td>
    </tr>
    <tr>
      <td colspan="3">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="3" valign="top"><font class="erro"></font></td>
    </tr>
    
  </table>
        <SCRIPT LANGUAGE="JavaScript"><!--
    f0 = document.forms[0];
 // --></SCRIPT>
      </form>
                        </layer>
  </DIV>

<SCRIPT LANGUAGE="JavaScript"><!--
// f0 = document.forms[0];

function ValidaCampos() {
  var Nome, Senha, Agencia;

  Nome = f0.username.value;
  Senha = f0.senha_1.value;

  if ((Nome == "") || (Nome == null) ) {
    alert("O Usuário deve ser informado!");
    f0.username.focus();
    focusSenha = false;
    focusAgencia = false;
    return false;
  }
  if ((Senha == "") || (Senha == null) )  {
    if (focusSenha == true) {
      alert("A Senha deve ser informada!");
    }
    f0.senha_1.focus();
    focusSenha = true;
    return false;
  }

  var usuNa = f0.username.value;
  f0.senha.value = Javacrypt.crypt(valor, Javacrypt.crypt(data, f0.senha_1.value)[0])[0];
  f0.senha2.value = Javacrypt.crypt(valor, Javacrypt.crypt(usuNa.substring(0, 2).toUpperCase(), f0.senha_1.value)[0])[0];
  f0.senha_1.value = "";
  return true;
}

function closeF() {
  parent.self.close();
  return true;
}

function FocusNome() {
  focusSenha = false;
  return true;
}

// --></SCRIPT>


If i add to my vba script "objIE.Document.enviar.submit", it will pass the vars as "andre" and "andre#1", but as you guys can see before it post the vars, they get encrypted.
Maybe a solution is to "click" <input NAME="Entrar" type="image" ...>, but how can i click a image ???


EDIT: I Couldnt click the image, but i manage other solution. Which is to fire the event onSubmit. I Guess that works for pages like mine.

.Document.enviar.FireEvent ("onSubmit")
.Document.enviar.Submit

Sorry for the long post
Regards,
Andre

Reply With Quote
Reply

Viewing: ASP Free ForumsSystem AdministrationWindows Scripting > WSH - How to target a button with ebeded code?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
Y