|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 ![]() |
|
#2
|
|||||
|
|||||
|
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:
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. |
|
#3
|
|||
|
|||
|
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"> </td>
</tr>
<tr align="left" valign="middle">
<td class="GroupLabel" colcite="2" align="right" height="36" width="126"> </td>
<td class="GroupLabel" height="36" width="58">Transfer </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"> </td>
</tr>
<tr align="left" valign="middle">
<td class="RegularText" height="18" width="126"> </td>
<td height="18" width="58"> </td>
<td height="18" width="542"> </td>
<td height="18" width="18"> </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"> </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"> </td>
</tr>
</tbody></table>
</form>
|
|
#4
|
||||
|
||||
|
Oh, sorry...wasn't thinking about the frame. Try this:
objIE.FrameName.Document.FormName.Submit |
|
#5
|
|||
|
|||
|
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" |
|
#6
|
||||
|
||||
|
Quote:
|
|
#7
|
|||||
|
|||||
|
Line 29
Char 1 Objet doesn't support this propery or method: homebody 800A01B6 vb Code:
LINE 29: objIE.homebody.Document.StampForm.Submit Thanks for all your help, I really appreciate it. ![]() |
|
#8
|
|||
|
|||
|
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"> </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 |
![]() |
| Viewing: ASP Free Forums > System Administration > Windows Scripting > WSH - How to target a button with ebeded code? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|