Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WHS - clicking a button within a frame & onclick code 1

Status
Not open for further replies.

NEODARK

Technical User
Jul 16, 2007
9
US
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 "[URL unfurl="true"]www.site.com"[/URL]

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
[b]'The code works until it gets to the line below[/b]
[b]'It errors with object does not support this etc[/b]
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 :)
 
[1] The single major problem.
>objIE.Document.All.Forms("StampForm").Item("go").Click()
[tt]objIE.Document.All.StampForm.Item("go").Click()[/tt]

[2] I am not sure your 'do nothing is a good idea. Put some small duration to wscript.sleep. But for simple case, it won't kill.

[3] Your first page must have something named or have id "submit". Don't do that.

[4] Up there, you make setTimeout for 1 ms. Is it rocket science?

[5] >document.skipCheck=true
What kind of control, skipCheck, is it in that page? Look's improbable.
 
Also these.

[6]>Stop
There is no such thing in wsh. If you want to quit the oIEObj, do this.
[tt]wscript.quit[/tt]

[7] If you do not see [1] working, put "sufficient" time delay before it in an adhoc approach.
 
Thanks for your suggestions.

I've tried the objIE.Document.All.StampForm.Item("go").Click() approach, and still have no results. It's the same error (object does not support this, etc)

I've tried a WScript.Sleep 30000, which gives the page plenty of time to load, but there is still nothing, the error pops up after the 30 seconds pass.

The form is within a frame, and the submit button has an on click command, thus why I tried the click approach. This is the code of the form itself:

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>

I have no way to make changes to this code.

Thanks
 
>The form is within a frame
Now now. What kind of frame? what name/id? In the first post you mentioned frame. I don't see anything related to frame. Now you say the response page is in a frame. You have to make it explicit. The line I gave you is correct, as far as I am concerned, on the main window. It needs some tracing of reference to get to the button go. That's all. And you concealed the info related to frame and go that far in listing the form. What is more important to get the problem resolve, the form or the frame?
 
Without waiting for the detail of the setup (name/id) of the frame, use this.
[1']
>objIE.Document.All.Forms("StampForm").Item("go").Click()
[tt]objIE.document.frames(0).document.all.StampForm.Item("go").click()[/tt]
(There are many variations possible.)
 
Awesome tsuji, that did it!!!

I had to use

objIE.document.frames("nameofframe").document.all.StampForm.Item("go").click()

Thanks so much man for sticking with me

Sends *e-beer*

cheers!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top