So my overall goal is to scrape data from a table that is behind a security wall. I have done the code to launch IE and input the security creditals however the code I have for clicking the Submit button isn't working. The webpage I am working with is:
https://www.myfueltanksolutions.com/validate.asp
I have put the code below:
Private Sub CommandButton1_Click()
Dim i As SHDocVw.InternetExplorer
Set i = New InternetExplorer
i.Visible = True
i.navigate ("https://www.myfueltanksolutions.com/validate.asp")
Do While i.readyState <> READYSTATE_COMPLETE
Loop
Dim idoc As MSHTML.HTMLDocument
Set idoc = i.document
idoc.all.CompanyID.Value = "CompanyID"
idoc.all.UserId.Value = "UserID"
idoc.all.Password.Value = "Password"
Dim ele As MSHTML.IHTMLElement
Dim eles As MSHTML.IHTMLElementCollection
Set eles = idoc.getElementsByTagName("button")
For Each ele In eles
If ele.Name = "btnSubmit" Then
ele.Click
Else
End If
Next ele
End Sub
CodePudding user response:
btnSubmit
is not a button, it is an image.
Private Sub CommandButton1_Click()
Dim i As SHDocVw.InternetExplorer
Set i = New InternetExplorer
i.Visible = True
i.navigate ("https://www.myfueltanksolutions.com/validate.asp")
Do While i.readyState <> READYSTATE_COMPLETE
Loop
Dim idoc As MSHTML.HTMLDocument
Set idoc = i.document
idoc.all.CompanyID.Value = "CompanyID"
idoc.all.UserId.Value = "UserID"
idoc.all.Password.Value = "Password"
Dim ele As MSHTML.IHTMLElement
Dim eles As MSHTML.IHTMLElementCollection
'Set eles = idoc.getElementsByTagName("button")
Set eles = idoc.getElementsByTagName("img")
For Each ele In eles
If ele.Name = "btnSubmit" Then
'ele.Click
ele.parentNode.Click ' click the <a> that contains this element
Else
End If
Next ele
End Sub
The submit button is just calling a javascript function, so you could skip finding the button all togeather.
idoc.parentWindow.execScript "submitForm();"