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, Any Versions    
 
   
JimCarney6
post Nov 19 2018, 05:13 PM
Post#1


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


I'm trying to do something not too hard with VBA/access 2016, internet explorer 11.

i'm trying to launch a web page & login into it automatically. this is the basic code:

Sub GotoSite(strURL As String)

Dim IE As New SHDocVw.InternetExplorer

'make IE visible then open website
IE.Visible = True
IE.Navigate strURL '"https://atlasbridge.com/default.aspx"

'check if internet explorer is ready otherwise add 1 sec & loop
Do While IE.ReadyState <> READYSTATE_COMPLETE
'neither line works, but i've been told not neccessary; doesnt sem
'IE.Application.wait Now + TimeValue("00:00:01")
'Application.wait DateAdd("s", 1, Now)
Loop

IE.Document.Forms("form1").elements("txtUserName").Value = "*****" 'username
IE.Document.Forms("form1").elements("txtPassword").Value = "*****" 'password
IE.Document.Forms("form1").elements("cmdLogin").Click 'click command button

End sub

the user name & passwords the code will fill in i have **** here for obvious reasons, but i'm getting error 424 object required on
IE.Document.Forms("form1").elements("cmdLogin").Click

but when i inspect the webpage cmdLogin seems to be the buttons name. Am I missing something obvious? if i replace the website code with the following two lines on wikipedia it works fine, so all i can think is i've got the button's name wrong, but it looks correct to me.
IE.Document.Forms("searchform").elements("search").Value = "STAR WARS" 'password
IE.Document.Forms("searchform").elements("go").Click 'click command button
'https://en.wikipedia.org/wiki/Main_Page


"https://atlasbridge.com/default.aspx" is the webpage i'm trying to break down.

thank you
-Jim
Go to the top of the page
 
isladogs
post Nov 19 2018, 05:27 PM
Post#2


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


Change this from a Sub to a Function.
Tested and it works though obviously I can't test the login part

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
R. Hicks
post Nov 19 2018, 05:34 PM
Post#3


UA Forum Administrator
Posts: 40,505
Joined: 8-February 00
From: Birmingham, Alabama USA


QUOTE
Change this from a Sub to a Function.

Just curious as to why …
The routine does not return a value, so a Sub routine should be all that is needed.
The main difference is that a Function returns a value whereas a Sub routine does not.

R.

--------------------
Ricky Hicks
Birmingham, Alabama USA
Go to the top of the page
 
JimCarney6
post Nov 19 2018, 05:41 PM
Post#4


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


I changed it to a function, but no joy. still sticks on the cmdLogin click.
-Jim
Go to the top of the page
 
JimCarney6
post Nov 19 2018, 05:44 PM
Post#5


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


One more thing. i tried adding the website as a trusted site in my IE, but then the code wouldn't run at all. it would hang up straight away. now that confuses me even more.
-Jim
Go to the top of the page
 
isladogs
post Nov 19 2018, 05:45 PM
Post#6


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


Without knowing the login details, I can't test that line.
I'll try on another site and see if that gives any clues

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
June7
post Nov 19 2018, 05:49 PM
Post#7



Posts: 968
Joined: 25-January 16



I have code to do this and works just fine as a Sub procedure. However, code is a bit different.

CODE
        Dim oBrowser As InternetExplorer
        Set oBrowser = New InternetExplorer
        oBrowser.Silent = True
        oBrowser.Navigate "https://login.ihserc.com/login/erc?"
        oBrowser.Visible = True
        Do
            'Wait till the Browser is loaded
        Loop Until oBrowser.ReadyState = READYSTATE_COMPLETE
        oBrowser.Document.all.Item("subAcctLoginName").value = "XXX"
        oBrowser.Document.all.Item("subAcctPassword").value = "XXX"
        oBrowser.Document.all.Item("Submit").Click


I tested with your URL, and the following line works:

oBrowser.Document.all.Item("cmdLogin").Click

With your original code, just change to:

IE.Document.all.Item("cmdLogin").Click

Of course, I get 'Invalid login information' result but the button click works.
This post has been edited by June7: Nov 19 2018, 06:04 PM

--------------------
Attachments Manager is below the edit post window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
DEBUG! DEBUG! DEBUG! http://www.cpearson.com/Excel/DebuggingVBA.aspx
Go to the top of the page
 
JimCarney6
post Nov 19 2018, 05:50 PM
Post#8


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


if you submit fake credentials it'll just not let you login but you'll get a password error message which on one hand would tells us it's "clicking" the button. i know it's putting in the user name & password as i see that happening as i line by line it & if i manually click login it lets me in. i ran the code with necessary name changes on wikipedia and it was ok. when i inspect the element on the command button it looks to me like i have the correct name. so i'm stumped a bit.

thank you for your help & any ideas!!
-jim
Go to the top of the page
 
JimCarney6
post Nov 19 2018, 05:52 PM
Post#9


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


June, thank you. just saw your reply & i'll run this tomorrow!
-Jim
Go to the top of the page
 
JimCarney6
post Nov 19 2018, 05:59 PM
Post#10


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


And we have a winner! June7 thank you very much, just replacing my last line with your oBrowser.Document.all.Item("cmdLogin").Click (i changed oBrowser to my IE.) and it works. so apparently this website for some reason worked with Document.all.Item but not .Forms("form1").elements("cmdLogin"). now what i would like to know is why, but i'll be moving on in the meantime. i need to try this to a few websites so i'll experiment in methods and see if i can figure out why. Much appreciated on the help. i didnt really want to get stuck on the "click".
-Jim

edit. this is a very uninformed theory, but the reason why my code worked on wikipedia but not the other website, i think... wikipedia had this element class as a search button. whereas the other website is labeling it as an "image". they might be laying a gif over the button & perhaps that was causing my issue. or some such.
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    18th November 2019 - 07:47 PM