Results 1 to 5 of 5

Thread: How to fill a form and click a button in IE with VBA?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2020
    Posts
    3

    How to fill a form and click a button in IE with VBA?

    Hello,
    I am trying to put NUM1 and NUM2 into an online form, click BUTTON1 to submit, and in a pop-up, click BUTTON2 to verify, all automatically through VBA in Excel.
    The VBA and HTML are attached, I just don't know which parts of the HTML connect to which parts of the VBA.....
    Guidance would be more than welcome.

    Codes here and in attachments:

    VBA:
    Code:
    Sub VBFORUM()
    Dim NUM1 As Long
    Dim NUM2 As Long
    NUM1 = 1
    NUM2 = 1
    
    Set browser = CreateObject("internetexplorer.application")
    browser.Visible = False
    browser.navigate ("https://www.domain.tld/a/b")
    Do
    DoEvents
    Loop Until browser.readyState = 4
    
    'browser form
    browser.document.getElementBy????("PART1").Value = NUM1
    browser.document.getElementBy????("PART2").Value = NUM2
    browser.document.getElementBy????("BUTTON1").Focus
    browser.document.getElementBy????("BUTTON1").Click
    
    'pop-up
    browser.document.getElementBy????("BUTTON2").Focus
    browser.document.getElementBy????("BUTTON2").Click
    
    End Sub
    
    
    
    HTML:
    
    'the main form
    
    <form>
    <div spacing="16px" class="Stack__Children-sc-16xlpz3-0 jshVIz">
    <div class="PlaceBidPanelStyledComponents__Balance-sc-1d4g4yt-5 vuPPg">
    <span class="Dot-sc-1sfyc4r-0 hdakGN">
    </span>
    <div class="text__Small-yikanu-11 irDADt">Available balance: 0.00</div>
    </div>
    <div class="PlaceBidPanelStyledComponents__BidAmountInput-sc-1d4g4yt-4 icDAlK">
    
    'the NUM1 input
    <span class="TextInputStyledComponents__OutlinedInputWrapper-icv573-0 kGMitR">
    <input font-size="14px" inputmode="numeric" pattern="[0-9]*[.]?[0-9]+" placeholder="Your Bid" type="text" class="TextInputStyledComponents__OutlinedInput-icv573-2 TextInput___StyledOutlinedInput-pale85-0 kJFYpC" value="0">
    <div class="text__Tiny-yikanu-12 dfAtUI">HNS</div>
    </span>
    </div>
    <div class="PlaceBidPanelStyledComponents__BidAmountInput-sc-1d4g4yt-4 icDAlK">
    
    'the NUM2 input
    <span class="TextInputStyledComponents__OutlinedInputWrapper-icv573-0 kGMitR">
    <input font-size="14px" inputmode="numeric" pattern="[0-9]*[.]?[0-9]+" placeholder="something" type="text" class="TextInputStyledComponents__OutlinedInput-icv573-2 TextInput___StyledOutlinedInput-pale85-0 kJFYpC" value="">
    <div class="text__Tiny-yikanu-12 dfAtUI">HNS</div>
    </span>
    </div>
    <div class="Stack__Children-sc-16xlpz3-0 jshVIz PlaceBidPanelStyledComponents__ReviewAndPlace-sc-1d4g4yt-3 hXNSfG" spacing="16px">
    <div class="text__Small-yikanu-11 gqADuO">Your total lockup: 0.00</div>
    
    'the BUTTON1 click
    <button to="[object Object]" type="submit" class="BUTTON1 BUTTON1">Review & place</button>
    </div>
    </div>
    </form>
    
    ///////////////////////////////
    
    'the pop-up
    
    <div role="dialog" aria-labelledby="dialog-title" aria-describedby="dialog-description" class="ModalStyledComponents__Dialog-kg1c2c-4 byksVC">
    <h2 id="dialog-title" class="ModalStyledComponents__DialogTitle-kg1c2c-1 ioFXlQ">Something</h2>
    <div id="dialog-description" class="ModalStyledComponents__DialogDescription-kg1c2c-2 dnALGG">Something</div>
    <div class="ConfirmBidModal___StyledDiv-sc-1vaogju-0 dGLTpr">
    <div class="ModalHeaderMinimal___StyledDiv-kjnfb2-0 iMMCNo">
    <div class="ModalHeaderMinimal___StyledDiv2-kjnfb2-1 cpKJYi">
    <div class="text__Large-yikanu-8 egtApc" style="width: 100%;">Review Your Bid</div>
    </div>
    <div class="ModalHeaderMinimal___StyledDiv3-kjnfb2-2 iMHCnB">
    <button class="ModalStyledComponents__CloseButton-kg1c2c-0 kpxkTf">
    <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path d="M1 15L14.9997 1.00036" stroke="#022047" stroke-width="2" stroke-linecap="round">
    </path><path d="M1 1L14.9997 14.9996" stroke="#022047" stroke-width="2" stroke-linecap="round">
    </path>
    </svg>
    </button>
    </div>
    </div>
    <h1 class="text__Header-yikanu-5 ConfirmBidModal___StyledHeader-sc-1vaogju-1 eApDrh">header/</h1>
    <div class="Stack__Children-sc-16xlpz3-0 jshVIz ConfirmBidModal___StyledStack-sc-1vaogju-2 hiENXz" spacing="16px">
    <div class="Stack__Children-sc-16xlpz3-0 jshVIz ConfirmBidModal___StyledStack2-sc-1vaogju-3 WktYa" spacing="16px">
    <div>
    <div class="ConfirmBidModal___StyledDiv2-sc-1vaogju-4 hMArqN">
    <div class="text__Regular-yikanu-10 ePvwlm">Bid amount</div>
    <div class="text__Regular-yikanu-10 lbLpXu">0.00</div>
    </div>
    </div>
    <div>
    <div class="ConfirmBidModal___StyledDiv2-sc-1vaogju-4 hMArqN">
    <div class="text__Regular-yikanu-10 ePvwlm">Added blind</div>
    <div class="text__Regular-yikanu-10 lbLpXu">0.00</div>
    </div></div><div><div class="ConfirmBidModal___StyledDiv2-sc-1vaogju-4 hMArqN">
    <div class="text__Regular-yikanu-10 ePvwlm">Mining Fee</div>
    <div class="text__Regular-yikanu-10 lbLpXu">0.00</div>
    </div>
    </div>
    <div>
    <div class="ConfirmBidModal___StyledDiv2-sc-1vaogju-4 hMArqN">
    <div class="text__Regular-yikanu-10 cHzhKE">Total</div>
    <div class="text__Regular-yikanu-10 kHJUwj">0.00</div></div>
    </div>
    </div>
    <div spacing="16px" class="Stack__Children-sc-16xlpz3-0 jshVIz"><div class="text__Tiny-yikanu-12 dMEdrn">Guaranteed safe & secure checkout</div>
    
    'the BUTTON2 click
    <button class="BUTTON2">Place bid</button>
    </div>
    </div>
    </div>
    </div>
    Attached Files Attached Files

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to fill a form and click a button in IE with VBA?

    browser.document.getElementBy????("PART1").Value = NUM1
    as all input and other elements are anonymous (no names or IDs), the only way would be to loop through all input elements and match some unique part of the inner html string
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2020
    Posts
    3

    Re: How to fill a form and click a button in IE with VBA?

    Thanks. It's true. Any code guidance? If you can help with just the PART1, NUM1 line, I could resolve the thread and figure the rest.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to fill a form and click a button in IE with VBA?

    try like
    Code:
    for each ele in browser.getelementsbytagname("input")
        if instr(ele.innerhtml, "placeholder="Your Bid") > 0 then ele.vale = num1
        if instr(ele.innerhtml, "placeholder="something") > 0 then ele.value = num2
    next
    typed in the browser so may contain typos or code errors

    i doubt that dealing with the popup would be so easy
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2020
    Posts
    3

    Re: How to fill a form and click a button in IE with VBA?

    Looks like it was a responsive site, so I couldn't grab the XML so easily. I used Selenium VBA in the end.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width