Consulting

Results 1 to 5 of 5

Thread: VBA: Problem clicking button on second page of a website form

  1. #1

    VBA: Problem clicking button on second page of a website form

    I am trying to automate the filling of a form, clicking submit, and then after that, clicking another button on the second page. My code so far successfully fills out the form and clicks the button loading the second page. However, on the second page I cannot get the button to click. When stepping through the code it clicks the second page button so I have properly identified the button but it is like the webpage is no longer selected when the code is running. Any help?

    The Button on the second webpage page:

    HTML Code:
     <tr><th colspan='3' style='padding-top:23px;padding-bottom:10px'><input type='button' value='Continue' class='v14b' onclick='if(verFrm())document.form1.submit();'></tr>


    My code to open the first webpage, fill out necessary forms, and click the button. Then to click the button on the next page.

    Sub FillICEForm()
    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")
    
    
    ie.Navigate "website"
    
    
    ie.Visible = True
    
    
    While ie.busy
    DoEvents
    Wend
    
    
    Application.Wait (Now + TimeValue("0:00:02"))
    
    
    ie.document.ALL("sf").Value = "1"
    ie.document.ALL("sd").Value = "100"
    ie.document.ALL("cd").Value = "100" 'sd/sf
    ie.document.ALL("ci").Value = "100"
    ie.document.ALL("r").Value = "100"
    ie.document.ALL("st").Value = "2" 'FROM SHEET
    
    'Submit first form
    
    
    Set the_input_elements = ie.document.getElementsByTagName("input")
    For Each input_element In the_input_elements
        If input_element.getattribute("class") = "v14b" Then
            input_element.Click
            Exit For
        End If
    Next input_element
    
    'Second page
    
    
    Set the_input_elements = ie.document.getElementsByTagName("input")
    For Each input_element In the_input_elements
        If input_element.getattribute("value") = "Continue" Then
            input_element.Click
            Exit For
        End If
    Next input_element
    
    
    
    
    
    
    End Sub

  2. #2
    I have found one thing that is different stepping through vs. when it runs through.

    When running it all the way through: After submitting the first form and loading the second page, if I look at the locals window for the IE object, it shows the old URL of the first page still even though the second page is loaded.
    When stepping through with F8: After submitting the first form and loading the second page, if I look at the locals window for the IE object it shows the new URL of the second page.

    Any reason for this difference? Why is it updating when stepping through but not when I run it?

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Why is it updating when stepping through but not when I run it?
    Timing.
    After the "Next" set some code to wait for IE to finish. One or two seconds would probably work, although I think that IE can return some value when it's ready for the next action.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  4. #4
    I wish it were so easy! Tried this but it does not help regardless of wait time.

  5. #5
    So I played around with adding even more waits than just after the next. I added weights all over the place and it works but only under one condition which is a useless one. When IE opens I have to click back into the VBA screen. If I don't it does not work as usual. I thought maybe then it would work if I just did not show the IE screen, but the same thing happens there. If I do not click in the VBA project are before the second page code runs it does not work. This is problematic because I plan on running this through multiple sets of inputs and need it to just go and not need me to click the VBA screen all the time. In any case it seems like a weird problem..

Tags for this Thread

Posting Permissions

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