+ Reply to Thread
Results 1 to 3 of 3

Submitting web form (cannot target submit button)

Hybrid View

  1. #1
    Registered User
    Join Date
    06-27-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2

    Submitting web form (cannot target submit button)

    Hi All,

    Hopefully someone has run into this, i searched the forum but could not find what i was looking for.

    Trying to automate a web submission using the following code:

    .Document.getElementsByName("Submit").Click
    It works perfectly when you have a normal form element, however the form i am trying to use has the submit button as follows:

    <script type="text/javascript">
    document.write('<br><input type="submit" name="Submit" value="Submit"><br/><br/>');
    </script>
    Any ideas?

    Thanks,
    Carlo

    FYI - below is the code in full:

    Sub Test()
     
    Set objIE = CreateObject("InternetExplorer.Application")
    name = InputBox("Enter Name")
     
    With objIE
    .Visible = True
    .Navigate "webpage here"
     
    Do While .Busy Or .ReadyState <> 4
    DoEvents
    Loop
     
     Set what = .Document.getElementsByName("name")
     what.Item(0).Value = offRef
    
    .Document.getElementsByName("Submit").Click
     
    Do While .Busy Or .ReadyState <> 4
    DoEvents
    
    Loop
    
    End With
    Set objIE = Nothing
     
    End Sub

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Submitting web form (cannot target submit button)

    getElementsByName returns a collection of elements, not a single element.

    You could try this but I can't guarantee it will work.
    .Document.getElementsByName("Submit")(0).Click
    Or this, assuming what.Item(0) refers to an element on the form.
    what.Item(0).form.submit
    Again, no guarantee.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    06-27-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Submitting web form (cannot target submit button)

    Norie,

    Thank you so much for the speedy reply and suggestions!

    Both of them work, however "what.Item(0).form.submit" seems to skip any validation javascript and force form submission.

    Thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1