0

I am trying to login Web page and fetch data however my login details are not getting update, i have tried all possibilities code from your forum, nothing is working for me

Below is my code, am getting attached error

Error Screen Shot

Sub test()
    Dim ie As Object
    Dim objCollection As Object
    Dim i As Integer

    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True
    ie.navigate "https://portal.expeditors.com/expo/login"

    Do While ie.Busy
        Application.Wait DateAdd("s", 1, Now)
    Loop

    'Get all the elements with input tag name
    Set objCollection = ie.document.getElementsByTagName("input")
    i = 0
    'Loop through all elements and find login form and fill it
    While i < objCollection.Length
        'Login name
        If objCollection(i).Name = "username" Then
            objCollection(i).Value = "bom-sumand"
        End If

        'Store login button in object
        If objCollection(i).Type = "submit" Then
            Set objElement = objCollection(i)
        End If
        i = i + 1
    Wend

    'Click login
    objElement.Click
    'Clean up
    Set ie = Nothing
End Sub
0m3r
  • 12,286
  • 15
  • 35
  • 71
Suman
  • 15
  • 9
  • What references have you checked ? – Imran Malek Oct 29 '18 at 07:53
  • Hello imran, thanks for the reply, not understood your question? can you please explain – Suman Oct 29 '18 at 08:01
  • I am not getting any error message while executing your code, please make sure you have added Internet controls reference in VBA editor TOOLS==> References==>Microsoft Internet Controls and try. – arun v Oct 29 '18 at 08:27
  • Try using Internet Explorer Medium if this continues. Might be GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}") - you will need to check – QHarr Oct 29 '18 at 08:45
  • Hello Arun, "Microsoft Internet Controls" already been added in References – Suman Oct 29 '18 at 09:09
  • Please verify same question – arun v Oct 29 '18 at 10:10

2 Answers2

1

I would use the available ids rather than looping to find the input boxes and sign in. These are much faster selector methods. You can add a .Focus. Also, swop InternetExplorer for InternetExplorerMeduim in some cases.

If problem continues check your internet settings in case site is blocked.

Open the URL via creating an IE instance direct.

Option Explicit
Public Sub Login()
    Dim ie As New InternetExplorer               'InternetExplorerMedium
    Const MAX_WAIT_SEC As Long = 5
    Dim t As Date, ele As Object
    With ie
        .Visible = True
        .navigate "https://portal.expeditors.com/expo/login"

        While .Busy Or .readyState < 4: DoEvents: Wend

        With .document

            Do
                DoEvents
                On Error Resume Next
                Set ele = .getElementById("j_username")
                On Error GoTo 0
                If Timer - t > MAX_WAIT_SEC Then Exit Do
            Loop While ele Is Nothing

            If ele Is Nothing Then Exit Sub

            With ele
                .Focus
                .Value = "bob"
            End With
            With .getElementById("j_password")
                .Focus
                .Value = "penny"
            End With

            .getElementById("signInBtn").Click

        End With

        While .Busy Or .readyState < 4: DoEvents: Wend

        Stop                                     '<== Delete me later
        .Quit
    End With
End Sub
QHarr
  • 83,427
  • 12
  • 54
  • 101
  • Getting error in this code "While .Busy Or .readyState < 4: DoEvents: Wend" and Error is Run-time error '-2147467259(80004005); Automation error Unspecified error – Suman Oct 30 '18 at 04:57
  • Try running again and use Dim ie As New InternetExplorerMedium – QHarr Oct 30 '18 at 07:55
  • Added "Dim ie As New InternetExplorerMedium " still same issue " Run-time error '-2147467259(80004005); Automation error Unspecified" – Suman Oct 30 '18 at 09:14
  • Is the site blacklisted by your security settings? – QHarr Oct 30 '18 at 09:14
  • yes, you are right, Automatically detect settings was disable in internet explore, now its working perfectly fine, thank you very much for great support – Suman Oct 30 '18 at 13:51
  • Ok, Message Noted – Suman Oct 31 '18 at 04:50
  • trying to navigate further getting run time error object required ie.navigate "https://expo.expeditors.com/expotr/expotr?action=com.expd.webapp.tracking.action.searches.SearchWebAction&SearchType=advancedshipment.BaseAdvancedShipmentSearch&reference=4220340930" – Suman Oct 31 '18 at 05:28
  • I don't think the error would be on that line. Which line is the error actually on? – QHarr Oct 31 '18 at 05:35
  • With .getElementById("j_username") .focus .Value = "bob" End With – Suman Oct 31 '18 at 05:47
  • try the edited version and let me know. There is a timed loop which you can increase from 5 seconds to wait for element to be present. – QHarr Oct 31 '18 at 05:59
  • yes, problem solved, further need to download all the documents linked under this references, URL "https://expo.expeditors.com/expotr/expotr?action=com.expd.webapp.tracking.action.document.DocumentImageDownloadWebAction&Type=Image.Get&xref=utbY7EWF98bNjBJgJX0qGubmHC8KZv9cJLDToqpU3UOz8RpExFamOA%3D%3D" – Suman Oct 31 '18 at 12:36
  • Please ask a new question and happy to help. Bear in mind if login based you will need to share the whole html of the page most likely. https://pastebin.com/ is good for that. – QHarr Oct 31 '18 at 12:38
  • Did you unaccept on that basis? What is missing please from the above? – QHarr Nov 01 '18 at 07:10
  • You said the problem was internet settings and needing a wait.... how does the other answer address either of those or inputting your info? – QHarr Nov 01 '18 at 07:11
  • As you mentioned that i should ask a new question hence i have posted a new question for this query, hope my understanding is correct? – Suman Nov 01 '18 at 07:47
  • yes, after internet setting, i am able to login web page via VBA excel, however i need to further develop this script hence i have posted new question – Suman Nov 01 '18 at 07:52
-1

Macro trying and failing to open a second instance of IE try this.

Sub test()
Dim ie As Object
Dim redURL As String
Dim objCollection As Object
Dim i As Integer

redURL = "https://portal.expeditors.com/expo/login"
On Error Resume Next
Set ie = GetObject(, "InternetExplorer.Application")
If Err Then
    Set ie = CreateObject("InternetExplorer.Application")
End If
On Error GoTo 0
ie.Visible = True
ie.Navigate redURL

Do While ie.Busy
Loop
End Sub
arun v
  • 852
  • 7
  • 19
  • Arun, thank you, am able to navigate web page however unable to update my login details – Suman Oct 29 '18 at 14:17