newbiethicky
Member
- Joined
- Sep 28, 2011
- Messages
- 7
- Programming Experience
- 1-3
I am trying to programmatically post to a textbox on a web form in IE - I have tried sendkeys - but I dont find them reliable or consistent - The code below is perfect - but only seems to work in a webbrowser control. How do I (click a button/select a radiobutton) send 'hello world' to a textbox on a webform in IE? By the way I would be happy to use the webbrowser control (so the code below would work) - but the webpage (which is not the one in the code below) runs locally on my machine (I dont have any control over it) and does not seem to work within a webbrowser control
Can anyone help??
PS go easy on me - I'm a Newbie/Thick
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Load particular page in WebBrowser object
WebBrowser1.Navigate("http://www.24directory.com.ar/submit.php")
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Beep()
' Part 1: Locate the Radio button "Regular links" and automatically click it
'<input type="radio" name="LINK_TYPE" value="normal">
Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
For Each curElement As HtmlElement In theElementCollection
Dim controlValue As String = curElement.GetAttribute("Value").ToString
If controlValue = "reciprocal" Then
curElement.InvokeMember("click")
End If
Next
' Part 2: Locate the Description RichTextBox and automatically input some text
'<textarea name="DESCRIPTION" rows="3" cols="37" class="text"></textarea>
theElementCollection = WebBrowser1.Document.GetElementsByTagName("textarea")
For Each curElement As HtmlElement In theElementCollection
Dim controlName As String = curElement.GetAttribute("name").ToString
If controlName = "DESCRIPTION" Then
curElement.SetAttribute("Value", "Some description")
End If
Next
' Part 3: Locate the Category ComboBox element and automatically choose one option
'<select name="CATEGORY_ID">
'<option label="[Top]" value="0" selected="selected">[Top]</option>
'<option label="|___Automotive" value="1">|___Automotive</option>
'<option label="| |___Alarms - Audio - Video" value="734">| |___Alarms - Audio - Video</option>
'</select>
theElementCollection = WebBrowser1.Document.GetElementsByTagName("select")
For Each curElement As HtmlElement In theElementCollection
Dim controlName As String = curElement.GetAttribute("name").ToString
If controlName = "CATEGORY_ID" Then
curElement.SetAttribute("Value", "10")
End If
Next
End Sub
End Class
Can anyone help??
PS go easy on me - I'm a Newbie/Thick
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Load particular page in WebBrowser object
WebBrowser1.Navigate("http://www.24directory.com.ar/submit.php")
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Beep()
' Part 1: Locate the Radio button "Regular links" and automatically click it
'<input type="radio" name="LINK_TYPE" value="normal">
Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
For Each curElement As HtmlElement In theElementCollection
Dim controlValue As String = curElement.GetAttribute("Value").ToString
If controlValue = "reciprocal" Then
curElement.InvokeMember("click")
End If
Next
' Part 2: Locate the Description RichTextBox and automatically input some text
'<textarea name="DESCRIPTION" rows="3" cols="37" class="text"></textarea>
theElementCollection = WebBrowser1.Document.GetElementsByTagName("textarea")
For Each curElement As HtmlElement In theElementCollection
Dim controlName As String = curElement.GetAttribute("name").ToString
If controlName = "DESCRIPTION" Then
curElement.SetAttribute("Value", "Some description")
End If
Next
' Part 3: Locate the Category ComboBox element and automatically choose one option
'<select name="CATEGORY_ID">
'<option label="[Top]" value="0" selected="selected">[Top]</option>
'<option label="|___Automotive" value="1">|___Automotive</option>
'<option label="| |___Alarms - Audio - Video" value="734">| |___Alarms - Audio - Video</option>
'</select>
theElementCollection = WebBrowser1.Document.GetElementsByTagName("select")
For Each curElement As HtmlElement In theElementCollection
Dim controlName As String = curElement.GetAttribute("name").ToString
If controlName = "CATEGORY_ID" Then
curElement.SetAttribute("Value", "10")
End If
Next
End Sub
End Class