2 Replies - 1848 Views - Last Post: 29 September 2011 - 02:17 AM Rate Topic: -----

#1 newbiethicky  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-September 11

Using vb.net to post to a webform in Internet Explorer

Posted 28 September 2011 - 10:47 AM

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="|&nbsp;&nbsp;&nbsp;|___Alarms - Audio - Video" value="734">|&nbsp;&nbsp;&nbsp;|___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



Is This A Good Question/Topic? 0
  • +

Replies To: Using vb.net to post to a webform in Internet Explorer

#2 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Using vb.net to post to a webform in Internet Explorer

Posted 28 September 2011 - 08:50 PM

Foes that code work in the WebBrowser control's DocumentCompleted event? In that case, add it to your radiobutton's CheckedChanged Event.
Don't be embarrased about being a noon, we were all there once.
HTH
Was This Post Helpful? 0
  • +
  • -

#3 newbiethicky  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-September 11

Re: Using vb.net to post to a webform in Internet Explorer

Posted 29 September 2011 - 02:17 AM

View PostjimmyBo, on 28 September 2011 - 08:50 PM, said:

Foes that code work in the WebBrowser control's DocumentCompleted event? In that case, add it to your radiobutton's CheckedChanged Event.
Don't be embarrased about being a noon, we were all there once.
HTH

Hi JimmyBo
Thanks for you quick reply -
Yes it does currently work on the DocumentCompleted event
Iam trying to write text in a textbox on a webform - essentially the problem I have is the the webform/site I want to write on exists locally on my machine and I have no influence on its developement etc - I want to paste text - which is really repetitive.

Unfortunately...
The webform/site does not seem to run within a webbrowser control - it only likes IE
So I am trying to develop an event that will find the textbox control on the site (running in IE) and write 'hello world' in it

If I dont run it in the winform/webbrowser control
The code does not find the instance of IE running and falls over at, for example
WebBrowser1.document.GetElementsByTagName("Input")
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1