Question WEB Automation

DRNiven

New member
Joined
Apr 29, 2011
Messages
1
Programming Experience
1-3
Need to be able to go to a website and upload file(s). I am using the code below to access the website and login, but when I get to the file upload part, I cannot communicate with the Browse for File control.

I am using a WebBrowser control on a form and the DocumentCompleted event is working for me to log in and go where I need to go on the web site.

I may be going about this all the wrong way to. Any help would be greatly appreciated.

PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
'Part 1: Load login page in Form_Load event
WebBrowser1.Navigate("Go to WEB Site")
EndSub

Private
Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
SelectCase intProcess
Case 1
'Part 2: Locate the Username TextBox and automatically input your username
ForEach curElement As HtmlElement In theElementCollection
Dim controlName AsString = curElement.GetAttribute("id").ToString
If controlName = "userid"Then
curElement.SetAttribute("Value", "Enter user ID")
EndIf
Next
'Part 3: Locate the Password TextBox and automatically input your password
theElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
ForEach curElement As HtmlElement In theElementCollection
Dim controlName AsString = curElement.GetAttribute("id").ToString
If controlName = "password"Then
curElement.SetAttribute("Value", "enter password")
EndIf
Next
'Part 4: Locate the "Sign In" Button and automatically click it
theElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
ForEach curElement As HtmlElement In theElementCollection
Dim controlName AsString = curElement.GetAttribute("name").ToString
If controlName = "login"Then
curElement.InvokeMember("click")
intProcess = 2
EndIf
'To get past the Message Box
SendKeys.Send("{Enter}")
Next
Case 2
'To get past the Message Box
SendKeys.Send("{Enter}")
WebBrowser1.Navigate("Go to the upload link")
intProcess = 3
Case 3
'File Upload Screen
theElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
ForEach curElement As HtmlElement In theElementCollection
Dim controlName AsString = curElement.GetAttribute("name").ToString
If controlName = "fileContents"Then
curElement.SetAttribute("Value", "c:\Test.text")
EndIf
Next

EndSelect
End
Sub
 
Back
Top