Question

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
Was it helpful?

Solution

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.

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top