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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to write script to click a button on a site

Status
Not open for further replies.
Sep 6, 2012
2
US
Hi, guys I'm new to the site and fairly new to VBScript. Is there a way to create a script to fill out a webform and then click a button to submit? I have the code working to fill out the form and select a necessary check box, but I can't figure out how to get it to submit.

Here's my current code without the button command:

Set IE = CreateObject("InternetExplorer.Application")
set WshShell = WScript.CreateObject("WScript.Shell")
IE.Navigate "IE.Visible = True
Wscript.Sleep 6000
IE.Document.All.Item("TEST").Value = "TEST"
IE.Document.All.Item("TEST").Value = "TEST"
IE.Document.All.Item("TEST").Value = "TEST@TEST.com"
IE.Document.All.Item("TEST").Value = "TEST"
IE.Document.All.Item("TEST").Value = "TEST"
IE.Document.All.Item("TEST").value = "TEST"
IE.Document.All.Item("TEST").value = "TEST"
IE.Document.All.Item("TEST").checked = true

This is part of the HTML that shows what I need to click:

<button onclick="sendSignup()" style="font-size: 18px; height: 30px; width: 120px;">Sign up</button>

Any help would be appreciated. Like I said I'm new to this. Thanks.
 
I think,

IE.Document.Form("myFormID").submit()

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Thanks for the post but I can't seem to get that to work either. I think the issue is that the button doesn't have an ID. I've tried sending keys and tabbing to the submit button and then sending enter but for some reason that won't stay consistent. Sometime's it will tab 2-3 links down or sometimes it won't tab down enough. I'm at a loss.
 
I should have asked before, but, what are you trying to accomplish? Does the form belong to you? There are different approaches to accomplish the same thing under different circumstances.

Because the button has not id or name, you will likely have to get the all button elements and traverse them to find the right one and then "click" it. This example loads an html file from my server, fills in the input boxes, finds and iterates all the button elements, and then "clicks" it when the right one is found.

Code:
Set IE = CreateObject("InternetExplorer.Application")
 set WshShell = WScript.CreateObject("WScript.Shell")
 IE.Navigate "[URL unfurl="true"]http://www.cilverphox.com/vbscripts/scratch2.html"[/URL]
 IE.Visible = True

wscript.sleep 1000 
IE.Document.All.Item("myInput1").Value = "peanut butter"
IE.Document.All.Item("myInput2").Value = "and"
IE.Document.All.Item("myInput3").Value = "jelly"
  		
set objButtons = IE.document.getElementsByTagName("button")
for each objButton in objButtons
	strText = objButton.innerhtml
	msgbox strText
	if (strText = "Bill") then
		msgbox "found the button!"
		objButton.click
		exit for
	end if
next

- Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
The form belongs to a contest website that allows hourly submissions to win a bad-ass shotgun.

Good luck MCBrandon710 .. but that shotgun is mine! Good day sir! [rednose]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top