Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


How to click a link from VBS.

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,48373
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> How to click a link from VBS.
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 How to click a link from VBS. - 6/15/2007 5:00:57 PM   
  tommytx

 

Posts: 8
Score: 0
Joined: 6/19/2005
From:
Status: offline
I understand how to grab text from the active window, but is there a way to click a button and dump text into a text box?

for example lets say we have this link on the page that is being called up with the routine below...
<a href="htttp://www.mysite.com">Click Me</a>
How can I send a command to activate the link above.


Set WshShell = WScript.CreateObject("WScript.Shell")
Set ie = CreateObject( "InternetExplorer.Application" )
ie.Navigate "http://www.mysite.com"
Do Until ie.ReadyState = 4
WScript.Sleep 10
Loop
ie.Visible = TRUE

WshShell.AppActivate "Real Estate"

msgbox ie.Document.Title

msgbox ie.document.body.innerHTML

z=document.getElementsByTagName('body')
msgbox "The inner data for the body tag is = " + z.innerHTML

ie.Quit
 
 
Post #: 1
 
 RE: How to click a link from VBS. - 6/15/2007 5:04:34 PM   
  tommytx

 

Posts: 8
Score: 0
Joined: 6/19/2005
From:
Status: offline
Let me clarify, its like two questions, how to simulate Clicking the word "Click Me" and also how to enter text into a text box.

Like for example
t = "Hello World"
document.joey.value=t
with the name value for the text box being joey.

Just wanted to clarify, as after reading it sounded like I wanted to activate "click Me" above and have it deliver text to a text box.
Actually 2 separate questions.

Thanks

(in reply to tommytx)
 
 
Post #: 2
 
 RE: How to click a link from VBS. - 6/15/2007 6:26:23 PM   
  tommytx

 

Posts: 8
Score: 0
Joined: 6/19/2005
From:
Status: offline
Here is an exact example of what I want to do in regards to text box.

<INPUT TYPE="text" NAME="sambo" value="Hello Dolly" SIZE="30">

I want vb script to get the info and write the info.. I know how to do it in javascript. but i cant get it to work in vb script.

if opened above by the IE

to fill box
ie.sambo.value = "This is new info in the text box."

to read box
dat = ie.sambo.value

Neither works in Vb is there another way..



(in reply to tommytx)
 
 
Post #: 3
 
 RE: How to click a link from VBS. - 6/16/2007 3:28:22 AM   
  dm_4ever


Posts: 2663
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
I am not sure about clicking a link but see if this helps you a bit...


      

< Message edited by dm_4ever -- 7/16/2007 7:28:54 AM >


_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to tommytx)
 
 
Post #: 4
 
 RE: How to click a link from VBS. - 6/16/2007 3:45:32 AM   
  tommytx

 

Posts: 8
Score: 0
Joined: 6/19/2005
From:
Status: offline
Thank you so much for sharing, that works perfect..

Now if anyone knows how to click a link that would be fantastic...
However I think I may even get this routine to simulate clicking a link, simply by grabbing the correct link and navigate to it since that is what happens when a link is clicked anyway.
Thanks again.. this will help a lot..

Again... if anyone has a link clicker it would be greatly appreciated..
Can be jscript, wsh script vbs or anything that can beused in a wsh file..

(in reply to dm_4ever)
 
 
Post #: 5
 
 RE: How to click a link from VBS. - 6/16/2007 8:42:12 AM   
  ehvbs

 

Posts: 2197
Score: 50
Joined: 6/22/2005
From: Germany
Status: online
Hi tommytx,

if you have a Link (= a) object, e.g.

    Dim oLINK : Set oLINK = document.getElementsByTagName( "a" )( 0 )

then

   oLINK.click

will go to href.

Bon voyage!

ehvbs

(in reply to tommytx)
 
 
Post #: 6
 
 RE: How to click a link from VBS. - 6/16/2007 9:04:45 AM   
  dm_4ever


Posts: 2663
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
I was thinking of trying .click ...glad to know it would work.

Thanks ehvbs!

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ehvbs)
 
 
Post #: 7
 
 RE: How to click a link from VBS. - 6/16/2007 9:23:08 AM   
  tommytx

 

Posts: 8
Score: 0
Joined: 6/19/2005
From:
Status: offline
Thanks for all the help, but the .click is still eating my lunch...
Here is what I have:

Option Explicit
Dim objIE : Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "about:blank"
objIE.Visible = True
objIE.Navigate "http://www.mysite.com/textbox.htm"
Do Until objIE.ReadyState = 4
  WScript.Sleep 500
Loop

' The following 3 commands work great.
' *******************************
msgbox objIE.Document.All.myform.sambo.value
objIE.Document.All.myform.sambo.value = "visualbasicscript"
objIE.Document.All.myform.submit

' The commented out commands below give an error "object required"
' *******************************************************
' Dim oLINK : Set oLINK = objIE.Document.All.myform.getElementsByTagName("Beach Realty")( 0 )
' oLINK.click

msgbox "All Done"

Can you see what i am doing wroing, i tried with and without the ALL but same error.
Am I using the link correct based on the enclosed html below.. "Beach Realty"
Thanks in advance for your help.


this is the htm file at textbox.htm commented out.

'<html>
'<head>
'<title>Tom's Page</title>
'</head>
'<body>
'<form name="myform" action="http://www.govhome4u.com" method="POST">
'<INPUT TYPE="text" NAME="sambo" value="Hello Dolly" SIZE="30"><br><br>
'<a href="Beach'>http://www.beachrealty.com">Beach Realty<a/><br><br>
'<a href="Resh'>http://www.reshrealtygroup.com">Resh Realty<a/><br><br>
'<input type="submit" value="Submit"><br><br>
'</form>
'</body>
'</html>
' Getting error "object required."



(in reply to dm_4ever)
 
 
Post #: 8
 
 RE: How to click a link from VBS. - 6/16/2007 10:09:18 AM   
  dm_4ever


Posts: 2663
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
This line: objIE.Document.All.myform.getElementsByTagName("Beach Realty")

Should still remain objIE.Document.All.myform.getElementsByTagName("a")

the (0) would represent the first link...(1) the second...and so on.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to tommytx)
 
 
Post #: 9
 
 RE: How to click a link from VBS. - 6/16/2007 1:57:27 PM   
  tommytx

 

Posts: 8
Score: 0
Joined: 6/19/2005
From:
Status: offline
Thanks so much ... you were right.. replcing the "Beach Realty" with the a made it work like a charm.
Isn't it amazing how someone as dumb as a rock can screw up the instructions so bad.... but with your help I got back on track.
You guys are absolute Miracle worker VBS experts.

Thanks again for all the great help..

This whole thread has been a super learning experience and has made one more string of information that someone can learn from and I would not be surprised if several other newbies are following this thread and learning also..


(in reply to dm_4ever)
 
 
Post #: 10
 
 RE: How to click a link from VBS. - 6/16/2007 2:15:32 PM   
  tommytx

 

Posts: 8
Score: 0
Joined: 6/19/2005
From:
Status: offline
OOPs! I thught I had a handle on it but I guess I don't.
When I tried to grab the second URL it failed...
I assumed if this was for the first url:
Dim oLINK : Set oLINK = objIE.Document.All.myform.getElementsByTagName("a")( 0 )    <-- This one worked.
Then I assumed this would be the second URL:
Dim oLINK : Set oLINK = objIE.Document.All.myform.getElementsByTagName("a")( 1 )    <-- This one failed.

But not so, it did not get anything..

As you can see above, the first one worked by redirecting to "beachrealty.com" and the second should have gone to "reshrealtygroup.com" but did not.
See the Url below..
When I went for the second one, I remove the first oLINK. Should I have left them both in place or shouild it have worked as above.

<form name="myform" action="http://www.govhome4u.com" method="POST">
'<INPUT TYPE="text" NAME="sambo" value="Hello Dolly" SIZE="30"><br><br>
'<a href="Beach'>http://www.beachrealty.com">Beach Realty<a/><br><br>
'<a href="Resh'>http://www.reshrealtygroup.com">Resh Realty<a/><br><br>

(in reply to tommytx)
 
 
Post #: 11
 
 RE: How to click a link from VBS. - 6/16/2007 3:09:12 PM   
  dm_4ever


Posts: 2663
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
If you use both of these at the same time it will error out because you are declaring a variable twice "Dim oLINK"

Dim oLINK : Set oLINK = objIE.Document.All.myform.getElementsByTagName("a")( 0 )
Dim oLINK : Set oLINK = objIE.Document.All.myform.getElementsByTagName("a")( 1 ) 

If you will use both then try
Dim oLINK
Set oLINK = objIE.Document.All.myform.getElementsByTagName("a")( 0 )
Set oLINK = objIE.Document.All.myform.getElementsByTagName("a")( 1 )

If you are still getting errors please post the error you are receiving and what you are trying.  If you are using On Error Resume Next...comment it out until you get all the bugs worked out.  This has been a learning experience for me too which is why I enjoy these forums.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to tommytx)
 
 
Post #: 12
 
 RE: How to click a link from VBS. - 11/27/2007 2:54:12 AM   
  hamboy

 

Posts: 94
Score: 6
Joined: 7/11/2005
Status: offline
Hi i am trying to do something similar




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

objIE.Visible = True
objIE.Navigate "http://www.myweb.com/result.html"
Do Until objIE.ReadyState = 4
WScript.Sleep 500
Loop


In result.html, there's a code:

<font class="headmd" face="arial,sans-serif" size="2">1 to 11 of 11</font>

How can I make vbscript scan result.html and put "11" value in a variable?

< Message edited by hamboy -- 11/27/2007 4:12:54 AM >

(in reply to dm_4ever)
 
 
Post #: 13
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> How to click a link from VBS. Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts