VBA IE Form Automation

craignet

New Member
Joined
Aug 4, 2012
Messages
11
Hi all,

Many posts along the same lines I know however am really struggling to get this working.

I've created code which logs into a website, clicks on a button which opens a new tab with forms, however I am unable to enter data into the forms despite trying various examples from other posts.

The code I have at the moment is:

Code:
''=======================================================
'' Program:   MyQuote
'' Desc:      Writes Data into online web form from data in workbook
'' Called by: Batch File (MyQuote.bat)
'' Call:      MyQuote
'' Info:
    ''This macro has been built improve the time it takes to gain a quotation from the MyQuote website.
    ''Once an agent has completed a quote on the inhouse system, they will run batch file (MyQuote.bat) which FTP's out the quote data, imports it into this
    ''workbook, and uses that data to fill the quote forms on the MyQuote website.
    ''The macro creates a new instance of Internet Explorer, navigates to the site, enters the username and password to login, and navigates through
    ''each question entering the variable extracted from our quote system.
'' Changes----------------------------------------------
'' Date         Programmer       Change
'' 13/01/2017   Craig               Written
''=======================================================
Sub MyQuote()
    
'Declaring the necessary variables.
    Dim IE              As Object


Dim Bton1 As HTMLGenericElement


'Set browser
        Set IE = CreateObject("InternetExplorer.Application")
        
'Log Off if already logged in
        IE.navigate "http://www.example.com/logout"
        
'Wait until IE has loaded
        Do Until IE.readyState = 4
            DoEvents
        Loop


'Navigate to My Quote Website
        IE.navigate "http://www.example.com/"
        
'Wait until IE has loaded
        Do Until IE.readyState = 4
            DoEvents
        Loop


'Enter values and login to My Quote Website
        IE.document.all.Item("UserName").Value = "user@example.co.uk"
        IE.document.all.Item("Password").Value = "abc"


'Find and press the submit button
        Set objCollection = IE.document.getElementsByTagName("button")


        If objCollection(i).Type = "submit" Then
            Set objElement = objCollection(i)
        End If


        objElement.Click


'Wait while IE re-loads...
        While IE.Busy
            DoEvents
        Wend
              
'Find and press the New Quote button
        Set objCollection = IE.document.getElementsByTagName("button")
        
        If objCollection(i).className = "btn btn-success btn-xs" Then
            Set objElement = objCollection(i)
        End If


        objElement.Click


'Wait while IE re-loads...
        While IE.Busy
            DoEvents
        Wend


'Find and press the Agree button on Credit Check pop up overlay
        For Each l In IE.document.getElementsByTagName("button")
            If l.className = "btn btn-success" Then l.Click
            Next
            
'Wait while IE re-loads...
        While IE.Busy
            DoEvents
        Wend
        
'Enter Registration
        '=====below is what is not working======
        'IE is now in a new tab with different URL if that helps
        IE.document.all.Item("Registration").Value = "AB12CDE"
        
        End With




End Sub

I am unable to supply the actual URL/passwords etc.. of the site, however below is a snippet of the HTML of the page and element I am trying to get working:

Code:
                                <input type="text" name="Registration" id="Registration" class="form-control reg-input" data-bind="value: Registration" placeholder="REGISTRATION">
                                <button id="btn-findVehicle" class="btn btn-primary" type="button" data-bind="click: $parent.findVehicle">Find your car </button>


I don't know if this is because I am trying to select an object and I am now in a new IE tab, but I've spent 10 hours trying to get this working without any luck.

Once this is fixed I can move on with mapping the other 40 fields, radio buttons, drop down menu's & submit buttons (wish me luck).

Any help and advice appreciated.

Regards

Craig
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top