On a WebPage opened by a Macro, how do perform a TAB action?
-
viernes, 10 de agosto de 2012 12:54
I was able to code a macro that opens an IE session, then navigates to a URL. These parts work.
The problem I need to solve is I need to perform a Tab action through the input text boxes. I am able to locate the input tag, issue a Click action, set the value. However, in order for Web app to work, I need to Tab off of the field after I set the value.
I have not found the Property that I can use to do this action.
The properties that I use in the Macro are:
sZipKmRadius.Value = "" 'Set the value of this field to NULL
sZipMileRadius.Focus 'Sets the Focus to this element
sZipKmRadius.Click 'Clicks on the element.
Does anybody know how to tab off of the field
Todas las respuestas
-
viernes, 10 de agosto de 2012 13:08
If the DOM does not provide a Tab method, I think you are stuck with a keystroke poker....
Did you try Sendkeys "{TAB}",True ?
- Propuesto como respuesta Learning and LearningEditor domingo, 12 de agosto de 2012 10:42
-
viernes, 10 de agosto de 2012 16:06
Forgive me on this but you introduced a few terms that I am not familiar with. I am a noivice at this.
DOM = Dynamic Object Model?
How would I found out what methods are in this DOM? How would I found out what DOM I am using.
What code would represent "Sendkey "{TAB}",True" or is that the actual code? If that is the actual code, then would that appear after I set the field to the value?
Below is my series of Subroutines:
Sub Control_Web_Access()
Dim appIE As Object 'This is the IE session
Dim sURL As String 'This is the actual URL of the Web Page
Dim sZipMileRadius As Object 'This the number of miles for the radius around the Zip Code
Dim sZipKmRadius As Object 'This the number of miles for the radius around the Zip Code
Dim DisplayApp As Boolean
Dim WebPageInputTag As Object 'each Tab that is labeled as Input
Call GetIE(appIE)
sURL = "http://www.freemaptools.com/find-zip-codes-inside-radius.htm"
DisplayApp = True
Call WebPageSession(appIE, sURL, DisplayApp)
'Hunt for a field:
'Set sZipMileRadius = appIE.Document.getElementsByName("tb_radius_miles")
Set sZipMileRadius = appIE.Document.getElementsByTagName("INPUT")
'If Not sZipMileRadius Then
' ' fill in first element named "tb_radius_miles", assumed to be the login name field
' sZipMileRadius(0).Value = "50"
'End If
For Each WebPageInputTag In sZipMileRadius
If WebPageInputTag.Name = "tb_radius" Then
' WebPageInputTag.Value = ""
WebPageInputTag.Click
Set sZipKmRadius = WebPageInputTag
End If
If WebPageInputTag.Name = "tb_radius_miles" Then
Set sZipMileRadius = WebPageInputTag
WebPageInputTag.Click
' WebPageInputTag.Value = "50"
sZipKmRadius.Click
End If
If WebPageInputTag.Name = "goto" Then
WebPageInputTag.Value = "44122"
End If
Next WebPageInputTag
sZipKmRadius.Value = ""
sZipMileRadius.Focus
' sZipMileRadius.Tab
sZipMileRadius.Value = "50"
sZipKmRadius.Click
End Sub
Sub GetIE(IESession As Object)
On Error Resume Next
Set IESession = CreateObject("InternetExplorer.Application")
End Sub
Sub WebPageSession(IESession As Object, sURL As String, Display As Boolean)
With IESession
.Navigate sURL
' uncomment the line below if you want to watch the code execute, or for debugging
.Visible = Display
End With
' loop until the page finishes loading
Do While IESession.Busy
Loop
End Sub- Propuesto como respuesta Learning and LearningEditor domingo, 12 de agosto de 2012 10:42
-
viernes, 10 de agosto de 2012 17:25
DOM = Document Object Model....and you are effectively using it in this app.
Put the sendkeys statement where these are located:
' sZipMileRadius.Tab
I think this will work since you have the html control's Focus.
-
viernes, 10 de agosto de 2012 17:47
OK, I followed your suggestion
I put the code:
appIE.SendKeys "{TAB}", True
Is this correct? When I do this I get an error 438:
Object doesn't support this property or method (Error 438)
So, now what are my options?
-
domingo, 12 de agosto de 2012 10:42Usuario que responde
SysWizard suggested to use only SendKeys
IE does not sipport the method.It is a vb statement.
Best Regards,
Asadulla Javed, Kolkata
---------------------------------------------------------------------------------------------
Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it solves the issue. -
domingo, 12 de agosto de 2012 11:02Why do you need to use the TAB key? I can extract any information from the webpage without using the tab.
jdweng
-
jueves, 16 de agosto de 2012 6:32Moderador
Hi Daniel,
Thanks for posting in the MSDN Forum.
Do you solved your issue? If you have solved it, would you please share your experience here?
Have a good day,
Tom
Tom Xu [MSFT]
MSDN Community Support | Feedback to us
-
jueves, 16 de agosto de 2012 12:31
How did you do that?
When I do:
1. Enter the data (the miles and zipcode)
2. Press the Go button within the macro, I receive nothing back.
Would you be able to post at least the important parts of the macro here on the forum?
-
jueves, 16 de agosto de 2012 15:05
I thought this was going to be real easy. It wasn't. the code below should solve all your problems
'add reference : Microsoft Internet Controls Sub Control_Web_Access() Dim appIE As Object 'This is the IE session Dim sURL As String 'This is the actual URL of the Web Page Dim sZipMileRadius As Object 'This the number of miles for the radius around the Zip Code Dim sZipKmRadius As Object 'This the number of miles for the radius around the Zip Code Dim DisplayApp As Boolean Dim WebPageInputTag As Object 'each Tab that is labeled as Input Call GetIE(appIE) sURL = "http://www.freemaptools.com/find-zip-codes-inside-radius.htm" DisplayApp = True Call WebPageSession(appIE, sURL, DisplayApp) Set sRadius = appIE.Document.getElementById("tb_radius") sRadius.Value = 50 * 1.609344 Set sRadius = appIE.Document.getElementById("tb_radius_miles") sRadius.Value = 50 Set zipcode = appIE.Document.getElementById("goto") zipcode.Value = "44122" Set tb_radius = appIE.Document.getElementById("tb_radius") tb_radius.Click Set sZipMileRadius = appIE.Document.getElementsByTagName("INPUT") For Each WebPageInputTag In sZipMileRadius If WebPageInputTag.Name = "Go" Then WebPageInputTag.Click finish = False output = Null Do Do While appIE.readyState <> 4 Or _ appIE.Busy = True DoEvents Loop Set output = appIE.Document.getElementById("tb_output") If output.Value <> "" Then If output.Value <> "" Then finish = True End If End If Loop While finish = False Exit For End If Next WebPageInputTag zipcodes = output.Value zipcodearrays = Split(zipcodes, ",") End Sub Function GetIE(IESession As Object) As Object On Error Resume Next Set IESession = CreateObject("InternetExplorer.Application") End Function Sub WebPageSession(IESession As Object, sURL As String, Display As Boolean) With IESession ' uncomment the line below if you want to watch the code execute, or for debugging .Visible = Display .Navigate sURL End With ' loop until the page finishes loading Do While IESession.readyState <> 4 Or _ IESession.Busy = True DoEvents Loop End Subjdweng
-
jueves, 16 de agosto de 2012 17:27
Uh, what specifically made this work ? Was it the ReadyState loop test ?
Also, can you explain this code: ?
If output.Value <> "" Then If output.Value <> "" Then finish = True End If End If -
jueves, 16 de agosto de 2012 20:58
I made a number of changes to the original code. I used getElementById instead of getElementsByTagName to uniquely identify some of the objects. A webpage has a combination of HTML code and Java code and you must wait for both to complete before searching for objects. So I test for a combination of readyState <> 4 and (actually an "or" in the code) appIE.Busy = True. In some cases these two test are not enough. So I add additional code to make sure objects fully load like the code I added in this example.
I also found setting the KM radius to "" and putting the radius in mides didn't work. so I enter both the miles and km.
jdweng
- Propuesto como respuesta Syswizard viernes, 17 de agosto de 2012 14:45
-
viernes, 17 de agosto de 2012 14:46
Nicely done Joel. Clearly, controlling web pages requires a constant check for the ReadyState Property.
- Editado Syswizard sábado, 18 de agosto de 2012 19:06
-
viernes, 17 de agosto de 2012 21:31
Wow! It worked!
I finally was able to apply the fixes you made to my macro and test it.
I have 1 final question.
How can you find out the number of element that were created after you do this statement:
zipcodearrays = Split(zipcodes, ",")
I really do appreciate your help on this! I now have 1 happy user and 1 entire happy department!
- Marcado como respuesta Tom_Xu_WXModerator martes, 21 de agosto de 2012 6:54

