PDA

View Full Version : click link in web page



geebee
08-29-2008, 05:48 AM
hi,

i have the following...

Public Sub secureTEST()


'https://secure.com/Transactions/Logon.asp

'This project includes references to "Microsoft Internet Controls" and
'"Microsoft HTML Object Library"

'Variable declarations
Dim myURL As String
Dim myURL33 As String


Dim strSearch As String

'Set starting URL and search string
myURL = "https://secure.com/Transactions/Logon.asp"
strSearch = "user"

'Make IE navigate to the URL and make browser visible
myIE.navigate myURL
myIE.Visible = True



'Wait for the page to load
Do While myIE.Busy Or myIE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop

'Set IE document into object
Set myDoc = myIE.document
Set o = myDoc.all.tags("A")
'M = o.Length: mySubmit = -1




Dim strpassword As String
strpassword = "something"

With myDoc.getElementsByName("UserName")(0)
.Value = strSearch
End With



With myDoc.getElementsByName("Password")(0)
.Value = strpassword
End With


With myDoc.getElementsByName("Client")(0)
.Value = "DDDD"
End With



'******************************************************
'put the focus on the IE window/secure, and simulate hitting ENTER key
'******************************************************
Dim lHwnd As Long
lHwnd = FindWindow("IEFrame", vbNullString) 'determine if there is IE open


If lHwnd <> 0 Then
'MsgBox "IE is open!", vbInformation, "IE"
ShowWindow lHwnd, SW_SHOWNORMAL
Dim XT As Long
XT = BringWindowToTop(lHwnd) 'brings the IE window to top
Windows.Application.SendKeys "{ENTER}"
SendKeys "{ENTER}"


'While myIE.Busy: DoEvents: Wend
For r = 0 To M - 1: zz = ""
zz = zz & "Link Index : " & r & " of " & o.Length - 1
zz = zz & String(3, vbCrLf)
'
zz = zz & "A . tabindex : " & o.Item(r).tabIndex
zz = zz & String(3, vbCrLf)
'
zz = zz & "A . tagname : " & o.Item(r).tagName
zz = zz & String(3, vbCrLf)
'
zz = zz & "A . href : " & o.Item(r).href
zz = zz & String(3, vbCrLf)
'
zz = zz & "A . type : " & o.Item(r).Type
zz = zz & String(3, vbCrLf)
'
zz = zz & "A . name : " & o.Item(r).Name
zz = zz & String(3, vbCrLf)
'
zz = zz & "A . innerhtml : " & o.Item(r).innerHTML
zz = zz & String(3, vbCrLf)
'
zz = zz & "A . outerhtml : " & o.Item(r).outerHTML
zz = zz & String(3, vbCrLf)
'
zz = zz & "A . rel : " & o.Item(r).rel
zz = zz & String(3, vbCrLf)
'
zz = zz & "A . rev : " & o.Item(r).rev
zz = zz & String(3, vbCrLf)
'
zz = zz & "A . id : " & o.Item(r).ID
zz = zz & String(3, vbCrLf)
MsgBox zz
If InStr(1, o.Item(r).innerHTML, "View Reports", vbTextCompare) Then
MsgBox "= F O U N D =" & vbCrLf & o.Item(r).innerHTML
o.Item(r).Click: Exit For
End If
Next


Else
MsgBox "IE isn't open!", vbInformation, "Window not found."
End If
'******************************************************
'end of put the focus on the IE window/secure, and simulate hitting ENTER key
'******************************************************

'Wait for the page to load
Do While myIE.Busy Or myIE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop

End Sub



for some reason the "o.Item(r).Click: Exit For" is not working. the link in
the web page is not being clicked programmatically. i got this to work in
another site, but not on this one. also, the debugger is pointing to the
following:
Set o = myDoc.all.tags("A")
I simply want the "view reports" link to be clicked programmatically via the code.

what do i need to do?

thanks in advance,
geebee

shamsam1
08-29-2008, 10:01 PM
how r u calling the function findwindow and showwindow

TomSchreiner
08-30-2008, 02:36 AM
Without seeing the actual page and determining what method of validation they are using, if any, I can only throw pennies at you.

Replace:
o.Item(r).Click
With:
o.Item(r).FireEvent "onclick"

stanl
08-30-2008, 04:03 AM
First guess: I am assuming the sendkeys of {ENTER} is meant to simulate a submit button and bring up a 2nd page, in which case Set o = myDoc.all.tags("A") is no longer valid on that page. .02 Stan

geebee
08-30-2008, 04:09 PM
stanl how do I make sure the set o = mydoc.all.tags("a") is valid on the new page?