link click not working

G

geebee

hi,

i have the following...

Public Sub ePremisTEST()


'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://epremis.etenet.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
'note because this code puts the focus on the IE application/window,
'you cannot step through the code to see it work. you have to RUN the code
'******************************************************
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")

what do i need to do?

thanks in advance,
geebee
 
J

Joel

If o.Item(r).Click has a ONCLICK then you need t select the item

o.Item(r).Select
o.Item(r).Click

You may want to put a watch on "o" . Highligh "o" with mouse then right
click and select watch. Run code until the ERROR occrus or put a break point
(F9) on the Select line. Open the + sign in the watch and look at the
properties that start with ON. The ones that are valid should NOT have NULL.

The watch window will only show the first 256 items so if your problem is
with an item greater than 256 then you need to set a varialbe to the item.
If you have more than 256 then do this

set testa = o.Item(r)
o.Item(r).Select
o.Item(r).Click

The add testa to watch.
 
G

geebee

hi,

but why is the debugger pointing to the Set o = myDoc.all.tags("A") line??

thanks in advance,
geebee
 
J

Joel

This is probably the 1st time you used the debugger. when you set a break
point it stops before the instruction is executed and highlight that line.
Pressing F8 steps one instruction at a time. F5 runs until the break point
is hit, the macro stops, or an error occurs.

I usually use this

Set o = myDoc.getelementsbytagname("A")

You may be getting an error.
 
J

Joel

Just another issue..You may not have a TAGGED item "A". I also in internet
explorer go to Menu - view _ source and look at the tagged item. Another
useful item is to put the all items onto a worksheet to easily veiw them

with sheets("Test")
RowCount = 1
for each itm in Mydoc.all

Range("A" & RowCount) = itm.innertext
Range("B" & RowCount) = left(itm.innerHTML,256) 'this can get very long
Range("C" & RowCount) = itm.class

RowCount = RowCount + 1
next itm
end with
 
J

Joel

Two more idaes

1) the wild card * works wit tag names

For Each Tag In myDoc.getelementsbytagname("*")
msgbox
Next Tag

2) Tags are listed as Tagid

So for debugging

with sheets("Test")
RowCount = 1
for each itm in Mydoc.all

Range("A" & RowCount) = itm.innertext
Range("B" & RowCount) = left(itm.innerHTML,256) 'this can get very long
Range("C" & RowCount) = itm.class
Range("D & RowCount) = itm.TagId

RowCount = RowCount + 1
next itm
end with
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top