none
how to select a combobox value in webbrowser vb.net? RRS feed

  • Question

  • How can I select a value in gmail registration specifically in the month and sex field? I noticed that it is different from other sites and I could not fit a code.
    Friday, May 26, 2017 7:05 PM

Answers

  • Hi LucFortunato,

    You could check the html source via chrome, which the code of gender like this:

    From the html source, it seems that it save Gender's value in a hidden control. we could retrieve related via the following code.

    Dim doc As HtmlDocument = WebBrowser1.Document
     Dim docelement As HtmlElement = doc.GetElementById("HiddenGender")
    Dim gender = docelement.GetAttribute("value")

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by jhon travolt Saturday, August 5, 2017 12:53 PM
    Thursday, June 8, 2017 8:29 AM
    Moderator

All replies

  • How can I select a value in gmail registration specifically in the month and sex field? I noticed that it is different from other sites and I could not fit a code.

     I am almost certain that it would be against their terms to register using an application that automates the registering process.

    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Friday, May 26, 2017 7:16 PM
    Friday, May 26, 2017 7:15 PM
  • How can I select a value in gmail registration specifically in the month and sex field? I noticed that it is different from other sites and I could not fit a code.


     I am almost certain that it would be against their terms to register using an application that automates the registering process.

    If you say it can`t be done then i`ll try it

    I don't want to automate the registration process, but just create a programm that makes it easy to register.
    Friday, May 26, 2017 7:29 PM
  • The following loads HTML into a web browser, pressing button1 assertion is used to locate a element (this is case a option element) by id, if not nothing find the option element and prep for setting a item as current. If not found do nothing else set the value in the drop down.

    Crude HTML

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    	<title>Untitled</title>
    </head>
    <body>
    <H3>Example Reply Form</H3>
    <FORM ACTION="mailto:user@provider.com" METHOD="POST" ENCTYPE="text/plain">
    	<P>
    		<INPUT TYPE="hidden" NAME="subject" VALUE="Example Form">
    		<SELECT NAME="age" id="MyAge">
    			<OPTION VALUE="under 18">under 18 </OPTION>
    			<OPTION SELECTED VALUE="18 to 25">18 to 25 </OPTION>
    			<OPTION VALUE="25 to 30">25 to 30 </OPTION>
    			<OPTION VALUE="30 to 40">30 to 40 </OPTION>
    			<OPTION VALUE="over 40">over 40 </OPTION>		
    		</SELECT> 
    		Your age<BR>
    		<INPUT TYPE="text" id="fName" NAME="name" size=40> Your name<BR>
    		<INPUT TYPE="text" NAME="email" size=40> Your e-mail
    	</P>
    	<P>
    		<TEXTAREA id="message" NAME="details" COLS=50 ROWS=10 WRAP="physical">Something about yourself</TEXTAREA>
    	</P>
    	<P>
    		I think this guide is 
    		<INPUT TYPE="radio" NAME="opinion" VALUE="great" checked> great 
    		<INPUT TYPE="radio" NAME="opinion" VALUE="middling"> middling 
    		<INPUT TYPE="radio" NAME="opinion" VALUE="very poor"> very poor 
    	</P>
    	<P>
    		<INPUT TYPE="submit" VALUE="Process Data">
    		<INPUT TYPE="reset" VALUE="Clear Data">
    	</P>
    </FORM> 
    </body>
    </html>
    

    Form code

    Public Class Form1
        Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
            WebBrowser1.DocumentText = My.Resources.BrowserText
        End Sub
        Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
    
            WebBrowser1.Document.GetElementById("fName").SetAttribute("value", TextBox2.Text)
            WebBrowser1.Document.GetElementById("message").SetAttribute("value", TextBox1.Text)
    
            Dim element As HtmlElement = WebBrowser1.Document.GetElementById("MyAge")
            If element IsNot Nothing Then
                Dim oldie As HtmlElement = element.GetElementsByTagName("option") _
                                       .Cast(Of HtmlElement).FirstOrDefault(Function(el) _
                                       el.GetAttribute("value") = "over 40")
    
                If oldie IsNot Nothing Then
                    oldie.SetAttribute("selected", "true")
                End If
            End If
        End Sub
    
        Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) _
            Handles WebBrowser1.DocumentCompleted
    
            Button1.Enabled = True
        End Sub
    End Class
    

    Before pressing the button

    After pressing the button


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, May 26, 2017 8:41 PM
    Moderator
  • I can't adapt it for gmail registration, the html code looks different. How to adapt it?

    Saturday, May 27, 2017 5:53 AM
  • UP!!!
    Wednesday, May 31, 2017 8:46 AM
  • Hi LucFortunato,

    You could check the html source via chrome, which the code of gender like this:

    From the html source, it seems that it save Gender's value in a hidden control. we could retrieve related via the following code.

    Dim doc As HtmlDocument = WebBrowser1.Document
     Dim docelement As HtmlElement = doc.GetElementById("HiddenGender")
    Dim gender = docelement.GetAttribute("value")

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by jhon travolt Saturday, August 5, 2017 12:53 PM
    Thursday, June 8, 2017 8:29 AM
    Moderator

  •  I am almost certain that it would be against their terms to register using an application that automates the registering process.


    I don't want to automate the registration process, but just create a programm that makes it easy to register.

    Yes that is also said by those persons who steel your money. They help you with spending it. 

    I'm by the way impressed how by Microsoft paid persons are helping with this. 



    Success
    Cor

    Thursday, June 8, 2017 10:01 AM
  • What?
    Saturday, August 5, 2017 12:54 PM