10 Replies - 995 Views - Last Post: 29 July 2013 - 07:26 AM Rate Topic: -----

#1 darko01   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 03-September 09

How to automatically enter data in these input boxes?

Posted 28 July 2013 - 09:07 AM

Hi. I am trying to create a program that automatically inputs text in a webpage input box.

It inputs the text properly, but first it needs to focus the text box properly.

Namely, when you manually enter the text, you normally first click on the input box, then input the text. In that way the box gets focused and the written text is black. - http://prntscr.com/1hu29e

However, when entering the text from the VB program, the text is entered in the box, but it is still grey. http://prntscr.com/1hu24t .. Because of that, the inputted text is not counted as valid and when the form is submitted, an error occurs saying that no info was entered. - http://prntscr.com/1hu2uw

The code that I am currently using:

WebBrowser1.Navigate("http://www.pagesjaunes.fr/")
WebBrowser1.document.GetElementById("quoiqui").Focus()
WebBrowser1.document.GetElementById("quoiqui").SetAttribute("Value", "Electricien")
Any suggestions on how to focus the box so it receives data properly? The site I am trying to do this is http://www.pagesjaunes.fr/ .

Thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: How to automatically enter data in these input boxes?

#2 lar3ry   User is offline

  • Coding Geezer
  • member icon

Reputation: 314
  • View blog
  • Posts: 1,296
  • Joined: 12-September 12

Re: How to automatically enter data in these input boxes?

Posted 28 July 2013 - 08:23 PM

Here's how I fill in an Input Box on an airport weather site.
            For Each element As HtmlElement In WebBrowser1.document.GetElementsByTagName("input")
                If element.GetAttribute("name") = "Stations" Then
                    element.InnerText = "CYQR"
                    Exit For
                End If
            Next


I think you should be able to change it to a GetElementById. See if you can modify this to work for you.

And later, when I want to sublit it with a click...

            For Each element As HtmlElement In WebBrowser1.document.GetElementsByTagName("input")
                If element.GetAttribute("value") = "Get the bulletins" Then
                    element.InvokeMember("click")
                End If
            Next


Was This Post Helpful? 0
  • +
  • -

#3 darko01   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 03-September 09

Re: How to automatically enter data in these input boxes?

Posted 29 July 2013 - 02:39 AM

Hey. Same thing happens with your code. The text enters the input box but is grey. Any suggestions?
Was This Post Helpful? 0
  • +
  • -

#4 IvSemenov   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 29-July 13

Re: How to automatically enter data in these input boxes?

Posted 29 July 2013 - 05:54 AM

try
WebBrowser1.document.GetElementById("quoiqui").SetAttribute("Value", "Test")



Typing Quickly so check if its correct:)
Was This Post Helpful? 0
  • +
  • -

#5 lar3ry   User is offline

  • Coding Geezer
  • member icon

Reputation: 314
  • View blog
  • Posts: 1,296
  • Joined: 12-September 12

Re: How to automatically enter data in these input boxes?

Posted 29 July 2013 - 06:37 AM

I've managed to fill in both required boxes on that site, but can't get the "Trouver" button to do the search. Perhaps someone more experienced in VB.Net HTML interaction can offer a suggestion. Anyway, here's the code...

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Navigate("http://www.pagesjaunes.fr/")
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        For Each element As HtmlElement In WebBrowser1.document.GetElementsByTagName("input")
            If element.Name = "quoiqui" Then
                element.InnerText = "Électricien"
                Exit For
            End If
        Next

        For Each element As HtmlElement In WebBrowser1.document.GetElementsByTagName("input")
            If element.Id = "ou" Then
                element.InnerText = "Paris"
                Exit For
            End If
        Next

        For Each element As HtmlElement In WebBrowser1.document.GetElementsByTagName("input")
            If element.Id = "btnValidSearch" Then
                element.InvokeMember("value") 'Here, I've tried "class", "type", "click"
                Exit For
            End If
        Next

    End Sub
End Class

This post has been edited by lar3ry: 29 July 2013 - 06:38 AM

Was This Post Helpful? 0
  • +
  • -

#6 ybadragon   User is offline

  • Home Owner
  • member icon

Reputation: 571
  • View blog
  • Posts: 2,647
  • Joined: 11-May 12

Re: How to automatically enter data in these input boxes?

Posted 29 July 2013 - 06:46 AM

Try using what Lar3y used but instead of element.InvokeMember("value") use element.InvokeMember("submit") you could also try looking into the RaiseEvent() method for HTML Element
Was This Post Helpful? 0
  • +
  • -

#7 IvSemenov   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 42
  • Joined: 29-July 13

Re: How to automatically enter data in these input boxes?

Posted 29 July 2013 - 06:50 AM

 Dim ParentElement As HtmlElement = WebBrowser1.document.GetElementById("btnValidSearch")
  Dim ChildElement As HtmlElement = ParentElement.FirstChild
   ChildElement.RaiseEvent("Trouver")



Try that to press the button
Was This Post Helpful? 0
  • +
  • -

#8 Jack Eagles1   User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 187
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Re: How to automatically enter data in these input boxes?

Posted 29 July 2013 - 06:57 AM

This works for me (adapted from lar3ry):

  For Each element As HtmlElement In WebBrowser1.document.GetElementsByTagName("input")
            If element.Name = "quoiqui" Then
                element.InnerText = "Électricien"
                Exit For
            End If
        Next

        For Each element As HtmlElement In WebBrowser1.document.GetElementsByTagName("input")
            If element.Id = "ou" Then
                element.InnerText = "Paris"
                Exit For
            End If
        Next
        WebBrowser1.document.GetElementById("btnValidSearch").InvokeMember("click")



This post has been edited by Jack Eagles1: 29 July 2013 - 06:58 AM

Was This Post Helpful? 1
  • +
  • -

#9 lar3ry   User is offline

  • Coding Geezer
  • member icon

Reputation: 314
  • View blog
  • Posts: 1,296
  • Joined: 12-September 12

Re: How to automatically enter data in these input boxes?

Posted 29 July 2013 - 07:16 AM

View PostJack Eagles1, on 29 July 2013 - 07:57 AM, said:

This works for me (adapted from lar3ry):

        WebBrowser1.document.GetElementById("btnValidSearch").InvokeMember("click")


Good call, Jack Eagles1!

It's odd, though. I would have thought that one of the things I tried would do the asme thing, but my code didn't work, and yours definitely does:

        For Each element As HtmlElement In WebBrowser1.document.GetElementsByTagName("input")
            If element.Id = "btnValidSearch" Then
                element.InvokeMember("click")
                Exit For
            End If
        Next


Was This Post Helpful? 0
  • +
  • -

#10 Jack Eagles1   User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 187
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Re: How to automatically enter data in these input boxes?

Posted 29 July 2013 - 07:17 AM

View Postlar3ry, on 29 July 2013 - 08:16 AM, said:

View PostJack Eagles1, on 29 July 2013 - 07:57 AM, said:

This works for me (adapted from lar3ry):

        WebBrowser1.document.GetElementById("btnValidSearch").InvokeMember("click")


Good call, Jack Eagles1!

It's odd, though. I would have thought that one of the things I tried would do the asme thing, but my code didn't work, and yours definitely does:

        For Each element As HtmlElement In WebBrowser1.document.GetElementsByTagName("input")
            If element.Id = "btnValidSearch" Then
                element.InvokeMember("click")
                Exit For
            End If
        Next



It's really weird actually. I was just spitballing when I wrote it - I wasn't sure if it would work because yours looks like it does pretty much the same thing.
Was This Post Helpful? 0
  • +
  • -

#11 JackOfAllTrades   User is online

  • Saucy!
  • member icon

Reputation: 6248
  • View blog
  • Posts: 24,016
  • Joined: 23-August 08

Re: How to automatically enter data in these input boxes?

Posted 29 July 2013 - 07:26 AM

Another one against the terms of service:

Translated from French:

Quote

To respect the privacy of the user, access to services is limited to manual operation. Any use of a robot is prohibited. In particular illegal automatic use of the Services for the constitution of commercial databases and automated prospecting email address.


Closed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1