UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Internet Explorer With VBA Part, Any Versions    
 
   
JimCarney6
post Nov 29 2018, 04:31 PM
Post#1


UtterAccess VIP
Posts: 1,943
Joined: 9-September 02
From: Florida


If anyone can give me some ideas i would very much appreciate it. i am having trouble manipulating a secure website. i cant provide access to the website, but any ideas on methods or code snipets i can try to implement & bug test would be helpful.

here's my goal, to log into the website (can do), go to its search page & then run a search for an item(can do). 1 & 3 work fine. 2 is the issue.

However, oddly if i manually break thru the code, step by step it all works fine. when it runs at full speed it fails on step 2. i'm trying to pause the execution long enough to let the page fully load(?) so the code will work as written.

here's the code in question.
Dim HTMLAs As MSHTML.IHTMLElementCollection


'get the search field i need by tag name
Set HTMLAs = HTMLDoc.getElementsByTagName("A")

'check if internet explorer is ready otherwise loop til it is
Do While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop

''loop til i find a matching href for the hyperlink takes me to the actual search screen
For Each HTMLA In HTMLAs
Debug.Print HTMLA.getAttribute("classname"), HTMLA.getAttribute("href"), HTMLA.getAttribute("rel")
'reads all the A tags, then looks for the correct hyperlink, then clicks it & drops out
If HTMLA.getAttribute("href") = "https://atlasbridge.com/search/reportsearch.aspx" Then
'li id="ctl00_PolicySearchMenuItem" <a href = "/search/reportsearch.aspx") https://atlasbridge.com/search/policysearch.aspx 'search button to goto search screen
HTMLA.Click
'HTMLA(10).Click 'works by index id
Exit For
End If
Next HTMLA

It's goal is to look up a hyper link:li id="ctl00_PolicySearchMenuItem" <a href = "/search/reportsearch.aspx") by looking at all the A tags on the page (after we've logged in), creates a collection & loops thru them til it finds the matching href & clicks it.

at full speed it always drops out at the 4th item in the collection, we need to get to 10. but it drops out consistently at the same spot. run the code slow, it loops great.

i've also tried putting
Do While IE.Busy Or IE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
in the loop hoping to slow it. but that didnt work either. it's like the collection Set HTMLAs = HTMLDoc.getElementsByTagName("A") only is loading the first 4 items. i have two pause loops even before i set the collection.

any ideas or even if i can freeze the code for 2 or 3 seconds would be great.
thank you in advance!
-Jim
Go to the top of the page
 
isladogs
post Nov 29 2018, 06:23 PM
Post#2


UtterAccess VIP
Posts: 1,702
Joined: 4-June 18
From: Somerset, UK


With a similar situation I used

CODE
With objIE
.....
        Do Until Not .Busy And .ReadyState = 4
        Loop
        
        DoEvents
        Sleep 3000
        DoEvents
...


The Sleep 3000 command creates a 3 second delay and is based on the Sleep API.
Adjust as necessary. Using two DoEvents is probably superfluous but it worked so I left it.

To use Sleep,,put the following in the declarations section of a standard module

CODE
#If VBA7 Then
    Declare PtrSafe Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
#Else
    Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
#End If

This post has been edited by isladogs: Nov 29 2018, 07:09 PM

--------------------
Go to the top of the page
 
JimCarney6
post Nov 29 2018, 06:42 PM
Post#3


UtterAccess VIP
Posts: 1,943
Joined: 9-September 02
From: Florida


Thank you for the suggestion, i'll try tomorrow or Monday & report back!
-Jim
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    20th October 2019 - 06:18 AM