Fire event with vba & InternetExplorer.Application to recalculate jquery form
Asked Answered
H

2

2

I'm trying to gather data from different websites. Therefore i'm using excel vba and start an internet explorer. I'm able to fill out a normal form. But sometimes i have to fill out a dynamic form with a jquery script behind.

The form will only enable all input fields (drop down menus), if the first 2 fields are filled out and an event is fired.

So my script is able to fill out the form but not to fire the "recalculation" event which is needed.

If you fill out the form manually with your mouse it works. How can i simulate this event?

This is my excel vba script:

Sub test_fill_form()

Dim url1 As String
Dim url2 As String
Dim url3 As String

url1 = "https://auto."
url2 = "ar"
url3 = "do.ch/selling/?step=1&uniqueid=8a7d2327-f426-4df7-8291-d6b55fc62e3c"

Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")

ie.Visible = True
apiShowWindow ie.hwnd, SW_MAXIMIZE
ie.navigate url1 & "ric" & url2 & url3

While ie.readyState <> 4: DoEvents: Wend

ie.document.all("Article_ArticleDetails_AutoRegistrationMonth").Click
ie.document.getElementById("Article_ArticleDetails_AutoRegistrationMonth").value = "1"
ie.document.getElementById("Article_ArticleDetails_AutoRegistrationYear").value = "2013"
End Sub
Hypodermis answered 30/10, 2013 at 18:5 Comment(1)
Thank you for your reply. the problem is, that when i fill the Dropdown Marke with a value: ie.document.getElementById("Article_ArticleDetails_AutoMakeId").value = "9" (BMW) there should be data loaded in the subsequent dropdown (Modell): ie.document.getElementById("Article_ArticleDetails_AutoModelId") if you do that with your mouse, data is loaded in the dropdown: AutoModelId (Modell). Is it possible to fire an event, that this data is loaded in that dropdown? thanks a lot!Hypodermis
H
3

Thanks for your Help

Now i have the solution:

ie.Document.getElementById("Article__").Click
ie.Document.getElementById("Article_ArticleDetails_").Focus
ie.Document.getElementById("Article_ArticleDetails_").Value = "9"

'This will run the java script / fire the recalc event
ie.Document.parentWindow.execScript "registrationUpdate()", "JavaScript"

Thanks all.

Hypodermis answered 31/10, 2013 at 6:31 Comment(0)
D
1

For the link provided the form has disabled dropdown but it has the options element in it so you may set disabled as false and can do further processing. (The dropdown are not waiting for ajax request to get filled)

Sub test_fill_form()

Dim url1 As String
Dim url2 As String
Dim url3 As String

url1 = "https://auto."
url2 = "ar"
url3 = "do.ch/selling/?step=1&uniqueid=8a7d2327-f426-4df7-8291-d6b55fc62e3c"

Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")

ie.Visible = True
'apiShowWindow ie.Hwnd, SW_MAXIMIZE
ie.navigate url1 & "ric" & url2 & url3

While ie.readyState <> 4: DoEvents: Wend

ie.document.all("Article_ArticleDetails_AutoRegistrationMonth").Click
ie.document.getElementById("Article_ArticleDetails_AutoRegistrationMonth").Value = "1"
ie.document.getElementById("Article_ArticleDetails_AutoRegistrationYear").Value = "2013"
ie.document.getElementById("Article_ArticleDetails_AutoMakeId").disabled = False
ie.document.getElementById("Article_ArticleDetails_AutoModelId").disabled = False
ie.document.getElementById("Article_ArticleDetails_AutoFuel").disabled = False
End Sub
Darmstadt answered 30/10, 2013 at 18:45 Comment(1)
@Hypodermis You may also call this URL directly auto.ricardo.ch/selling/_vehicleregistration/…Darmstadt

© 2022 - 2024 — McMap. All rights reserved.