Automate IE from VB - site with onclick = "return confirm('Update?')"

Hi,
I'm working on automating updating information on a web-site from VBA. The site use  "onclick = "return confirm('Update?')""  on the submit button.

Is there a way to "click" on the OK button on the alertbox?
Or somehow bypass the alertbox?

I'm using code like this:

    Set oIE = New SHDocVw.InternetExplorer
   oIE.Navigate "https://ddsmedlem.cbrain.dk/member.aspx?func=member.edit&mno=" & c.Value
   oIE.Document.all("Address1:_ctl0").Value = c.Offset(0, 3).Value
   oIE.Document.all("Address1:_ctl1").Value = c.Offset(0, 4).Value
   oIE.Document.all("submitButton").Focus
   oIE.Document.all("submitButton").Click

thor_ostergaardAsked:
Who is Participating?
 
AzraSoundCommented:
Do:

oIE.Document.all("formName").Submit


to bypass.
0
 
thor_ostergaardAuthor Commented:
Great - thanks
0
 
thor_ostergaardAuthor Commented:
Sorry - did'nt work - the information is not updated.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
thor_ostergaardAuthor Commented:
It is a .net site and the problem is properly a missing postback
0
 
AzraSoundCommented:
Is that the only javascript in the onclick of the submit button?  Clicking submit and directly submitting the form should have no change in the way the data is submitted.
0
 
thor_ostergaardAuthor Commented:
Nope - it is asp.net and there are a few more scripts
0
 
AzraSoundCommented:
It shouldn't matter what the server side language is...but if they coded the server side to specifically look for the button click, and not just the form submitted, then that will be a problem.

All I can think of is to trap for that event in your code, and try to automatically override the event handler with your own.  To do this, go to Project -> References and select HTML Object Library.  Then in your code module, place this at the top:

Private WithEvents btnSubmit As HTMLButtonElement (<~~ I think that is what it is called)

After navigating to the page, do:

Set btnSubmit = oIE.Document.all("submitButton")

You should be able to select, from your code module, the btnSubmit object in the top left dropdown box.  Once selected, you should see all the events in the right hand dropdown box (like any other control you place on a form, for example).  You should be able to select the onclick event.  Selecting it should give you something like:


Private Function btnSubmit_onclick() As Boolean

End Function


Inside that function, simply put:

btnSubmit_onclick = True


Then run your code as you had it before where it clicked the button to submit the form.
0
 
thor_ostergaardAuthor Commented:
It's not possible to declare the HTMLButtonElement with events :-(
0
 
AzraSoundCommented:
You must be writing your code in a standard .bas module.  It must be in a form or class module to utilize events of any kind.
0
 
thor_ostergaardAuthor Commented:
I'm running in a module now and the new eventhandler is called, but after the eventhandler on the site :-(
0
 
thor_ostergaardAuthor Commented:
Wow :-))))

btnSubmit.onclick = "" 

did the trix :-)

I'm running now. Thanks for your help.
0
 
AzraSoundCommented:
I guess that would make sense too...just delete the javascript code that executes when clicked.  Good job.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.