How to Automatically fill out web forms
I need to make a project that automatically connects to an internal server that has a web interface, fill out specific information, including picking items from a drop down list, textboxes, and then pressing the enter button.
Is this something I can handle in Vb 2005? or should I do it in Perl?
I believe the form is done in asp. Unfortunately the team that handles the service and servers are too busy to help me, so I need to access it from a user standpoint.
Even if you don't know how to do this, if you can point me in what direction I need to look for information that would be helpfull.
Thanks!
Re: How to Automatically fill out web forms
Kleinma has a good example on how to do this in the code bank here. He uses a COM object named SHDocVW. I have tried to do this in the past, and it works well, though frames appear to be inaccessible in .NET (from my experience) and now that my new program is hosted on a new Windows Server 2003 server, the Navigate command finishes loading the site. My code has worked on other systems, though, so I would be interested in learning what results you get.
Re: How to Automatically fill out web forms
I don't know if this can help you or not but...
This is some of my code on how I retrieve data from a SQL Database and then input the data into a ListBox:
vb Code:
Private Sub refreshGroupList()
lstEmailGroups.Items.Clear()
Dim sqlConn As New OleDb.OleDbConnection(sqlConnString)
Dim sqlStatement As String = "SELECT GroupName FROM EmailGroups ORDER BY GroupName"
Dim sqlCmdGroups As New OleDb.OleDbCommand(sqlStatement, sqlConn)
Dim groupDS As New DataSet
Dim groupDT As New DataTable
Dim sqlDA As New OleDb.OleDbDataAdapter
Try
sqlConn.Open()
sqlDA.SelectCommand = sqlCmdGroups
groupDS.Tables.Add(groupDT)
sqlDA.Fill(groupDT)
Catch ex As Exception
Response.Write("Error connecting to database! Please contact your administrator. " & vbNewLine & ex.Message)
Finally
sqlConn.Close()
End Try
For Each row As DataRow In groupDS.Tables(0).Rows
lstEmailGroups.Items.Add(Trim(row("GroupName")))
Next
End Sub
And here is code that adds data retrieved from a SQL Database to textboxes and drop down menus:
vb Code:
Private Sub btnEditData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditData.Click
lstBranch.ClearSelection()
lstDepartment.ClearSelection()
Dim counter As Integer
Dim userID As Integer
userID = lstUsers.SelectedItem.Value
Dim sqlConn As New OleDb.OleDbConnection(sqlConnString)
Dim sqlStatement As String = "SELECT * FROM Directory WHERE UserID = " & UserID
Dim sqlDA As New OleDb.OleDbDataAdapter
Dim sqlCommand As New OleDb.OleDbCommand(sqlStatement, sqlConn)
Try
sqlConn.Open()
sqlDA.SelectCommand = sqlCommand
DS.Tables.Add(DT)
sqlDA.Fill(DT)
txtFirstName.Text = DS.Tables(0).Rows(0)("First_Name").ToString
txtLastName.Text = DS.Tables(0).Rows(0)("Last_Name").ToString
txtNickname.Text = DS.Tables(0).Rows(0)("Nickname").ToString
txtNickname2.Text = DS.Tables(0).Rows(0)("Nickname2").ToString
txtNickname3.Text = DS.Tables(0).Rows(0)("Nickname3").ToString
txtExtension.Text = DS.Tables(0).Rows(0)("Extension").ToString
txtDID.Text = DS.Tables(0).Rows(0)("Direct_Dial").ToString
txtCellNum.Text = DS.Tables(0).Rows(0)("Cell_Number").ToString
txtDC.Text = DS.Tables(0).Rows(0)("DirectConnect").ToString
txtSalesNum.Text = DS.Tables(0).Rows(0)("Sales_Number").ToString
txtEmailAddress.Text = DS.Tables(0).Rows(0)("Email").ToString
txtSignOn.Text = DS.Tables(0).Rows(0)("Sign_On").ToString
counter = 0
For counter = 0 To lstBranch.Items.Count - 1
If lstBranch.Items(counter).Text = DS.Tables(0).Rows(0)("Branch").ToString Then
lstBranch.Items(counter).Selected = True
End If
Next
counter = 0
For counter = 0 To lstDepartment.Items.Count - 1
If lstDepartment.Items(counter).Text = DS.Tables(0).Rows(0)("Department").ToString Then
lstDepartment.Items(counter).Selected = True
End If
Next
sqlCommand.Dispose()
DS.Dispose()
DT.Dispose()
Catch ex As Exception
Response.Write("<script>alert(""Error connecting to the database. Please contact your administrator." & vbNewLine & ex.Message & """);</script>")
Finally
sqlConn.Close()
End Try
End Sub