PDA

View Full Version : Filling web form with validation.



Abdallah
04-21-2018, 01:17 PM
I'm trying to fill a form (you can see it here) (https://www.skatteetaten.no/person/skatt/hjelp-til-riktig-skatt/bolig-og-eiendeler/bolig-eiendom-tomt/formuesverdi/boligverdikalkulator/) via VBA controlling IE.
The problem is that after I manage to fill the textboxes with the values and click on "Neste", the values inserted get forgotten.
You can use IE consol with these commands to see the problem:

document.getElementById("Leilighet").click()
document.getElementsByName("opprinneligByggeAar")[0].value = "1985"
document.getElementsByName("boligensAreal")[0].value = "75"
document.getElementsByClassName("button")[0].click()

This is the VBA code I use so far:

Sub DoIt()
Dim IE As Object, element1, Rmax As Long, T as Integer, T2 as Integer
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = 1
T2 = Timer
Rfrsh:
IE.navigate "https://www.skatteetaten.no/person/skatt/hjelp-til-riktig-skatt/bolig-og-eiendeler/bolig-eiendom-tomt/formuesverdi/boligverdikalkulator/"
T = Timer
Do While IE.readystate <> 4 Or IE.busy
XEL: If Timer - T > 15 Then GoTo Rfrsh
If Timer - T2 > 50 Then GoTo NoNet
DoEvents
Loop
IE.document.getElementByID(Cells(3, 2)).Click '.Checked = True
IE.document.getElementsByName("opprinneligByggeAar").Item(0).Value = "1985"
IE.document.getElementsByName("boligensAreal").Item(0).Value = "75"
Set element1 = IE.document.getElementsByClassName("button")
For Each element1 In element1
If element1.innertext = "Neste" Then
element1.Click
End If
Next
Msgbox "Done!"
NoNet:
ex:
IE.Quit
Set IE = Nothing
Set element1 = Nothing
End Sub

Additional info:
The same problem existed when I used ".Checked = True" (shown in bold in the code) to check the radio button. And I could avoid that by clicking it instead.

Can the reason be related to the validation? And that the validation occurs only after a click or something? I tried clicking on the textboxes after filling them and I got the same result.

Thank you in advance & many thanks to everyone who helps others. This site helped me many many times.

SamT
04-23-2018, 10:21 AM
Moderator Bump