A
atlockhart
Hi, I am trying to create an automated web testing program that visits
a web page, fills out a form and uploads a file (from the same form in
a input type=file field). I am running into a problem when I try and
update the file input element and have read elsewhere that you can't
change it for security reasons. I have also read the work around that
says you need to grab the focus and then use sendkeys, however the
problem i'm having is with even getting a hold of the form file
element.
I keep getting the following exception in the catch block:
System.InvalidCastException: Unable to cast object of type
'mshtml.HTMLInputElementClass' to type 'mshtml.HTMLInputFileElement'.
at WebTester.CTestCase7.run()
I have tried using Ctype() to cast it to no avail.. I am pretty new to
VB, so any help would be great.. I am also open to other suggestions
as to how to post the data and file from the form to the aspx program..
thanks!
Here is my code:
Dim doc As mshtml.HTMLDocument
Dim Explorer As SHDocVw.InternetExplorer
Explorer = New SHDocVw.InternetExplorer()
Explorer.Visible = True
Explorer.Navigate("http://www.somewebsite.com/applications")
Try
doc = CType(Explorer.Document, mshtml.HTMLDocument)
Dim inputNameBox As mshtml.HTMLInputTextElement =
doc.getElementsByName("ApplicationsFirstName").item(, 0)
inputNameBox.value = "MyName"
Dim fileBox As mshtml.HTMLInputFileElement
fileBox =
doc.getElementsByName("ApplicationsFileUpload1:file").item(, 0)
Catch ex As Exception
Console.WriteLine(ex.Message())
Console.WriteLine(ex)
End Try
a web page, fills out a form and uploads a file (from the same form in
a input type=file field). I am running into a problem when I try and
update the file input element and have read elsewhere that you can't
change it for security reasons. I have also read the work around that
says you need to grab the focus and then use sendkeys, however the
problem i'm having is with even getting a hold of the form file
element.
I keep getting the following exception in the catch block:
System.InvalidCastException: Unable to cast object of type
'mshtml.HTMLInputElementClass' to type 'mshtml.HTMLInputFileElement'.
at WebTester.CTestCase7.run()
I have tried using Ctype() to cast it to no avail.. I am pretty new to
VB, so any help would be great.. I am also open to other suggestions
as to how to post the data and file from the form to the aspx program..
thanks!
Here is my code:
Dim doc As mshtml.HTMLDocument
Dim Explorer As SHDocVw.InternetExplorer
Explorer = New SHDocVw.InternetExplorer()
Explorer.Visible = True
Explorer.Navigate("http://www.somewebsite.com/applications")
Try
doc = CType(Explorer.Document, mshtml.HTMLDocument)
Dim inputNameBox As mshtml.HTMLInputTextElement =
doc.getElementsByName("ApplicationsFirstName").item(, 0)
inputNameBox.value = "MyName"
Dim fileBox As mshtml.HTMLInputFileElement
fileBox =
doc.getElementsByName("ApplicationsFileUpload1:file").item(, 0)
Catch ex As Exception
Console.WriteLine(ex.Message())
Console.WriteLine(ex)
End Try