Manipulate/Change/Form Fill data in webpages using the Webbrowser control - Page 5-VBForums
Page 5 of 14 FirstFirst ... 2345678 ... LastLast
Results 161 to 200 of 530

Thread: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

  1. #161
    New Member
    Join Date
    Aug 2007
    Posts
    5

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Hi This is one of the best examples I've seen. I'm just starting with some aspect of dotnet applications. I've scanned the thread but I cant see an answer to (what is probably very obvious once you know how) where the reference for the browser (used) comes from. Creating a new project from scratch where is the library for the browser version used here? The only refence in the distributed (zipped) project is to some dlls in bin/debug. What do I reference on an otherwise blank machine. What to I include in the setup for an exe based on this solution? Could you please expain this aspect of the solution please?

    appologies oif this is answered somewhere, but I did not see it.

    Many thanks

    Ian

  2. #162

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,251

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    sure.

    to get this setup you need to do the following

    1) create a new Windows Application in Visual Studio
    2) select "add reference" from the project menu, and under the .NET tab try to locate microsoft.mshtml (which is microsoft.mshtml.dll)

    If you don't see it there then try to search your compute rfor microsoft.mshtml.dll. if you don't have it at all, then you can download it from post #88 in this thread (it is also included in the download of the sample project in post #1)

    mshtml.dll is the HTML parsing engine. It is what allows you to parse and manipulate individual HTML elements in the browser control.

    So once you have that done its on to step 3

    3) right click in your toolbox (where all the controls are) and select "Choose Items" Then select the "COM components" tab when the dialog comes up.

    Scroll down and find "Microsoft Web Browser" and click the checkbox and then click OK. This will add the COM based webbrowser control to your toolbox so you can drag it to a form.

    That is all there is to it. From there you can use my example code to see how you actually do the manipulations of the webpage.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  3. #163
    New Member
    Join Date
    Aug 2007
    Posts
    5

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    thank you very much

    I had cracked 1&2 and was stubling over 3.

    Very helpful, much appreciated.

  4. #164
    Addicted Member
    Join Date
    Mar 2006
    Posts
    180

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Hi,

    Thanks for the the example code, its excellent.

    I hope you can help me with this.

    Im using your example to set the value of a drop down list, then i'm calling the postback javascript to populate a second drop down on the page which is based on the value of the first.

    So I have

    Code:
    DirectCast(GetCurrentWebForm.item("MakeAndModelSearch1:m_make"), MSHTML.HTMLSelectElement).value = "Subaru".ToUpper
            GetCurrentWebDoc.parentWindow.execScript("__doPostBack('MakeAndModelSearch1$m_make','')", "javascript")
    Then I want to set the value of the second dropdown - BUT, my code is trying to set it before the postback has occurred and it has been populated with values.

    Code:
                DirectCast(GetCurrentWebForm.item("MakeAndModelSearch1:m_model"), MSHTML.HTMLSelectElement).value = "Impreza".ToUpper
            GetCurrentWebDoc.parentWindow.execScript("__doPostBack('MakeAndModelSearch1$m_model','')", "javascript")
    I've tried to use a Thread.Sleep(2000) between the two bits of code, but although the thread sleeps it stops the first postback happening.

    How can I get around this? I need to hold off executing the second statement until the post postback has completed.

    Thanks

  5. #165

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,251

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    you need to use the DocumentComplete event of the webbrowser control. This event fires when a page has fully loaded. So when you do the first postback, the DocumentComplete event will fire when the page has posted back and reloaded in the browser.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  6. #166
    Addicted Member
    Join Date
    Mar 2006
    Posts
    180

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Great! Thanks.

    Another question, i'm working with this page

    https://www.bosbusinesscars.co.uk/Default.aspx

    How to I get the image on the left marked CAR SEARCH to click.

    I have this,

    DirectCast(GetCurrentWebForm.item("MakeAndModelSearch1:m_search"), MSHTML.HTMLImg).click()

    But I get a NullReferenceException, did I get the element name wrong?

    Thanks

  7. #167

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,251

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    here

    Code:
    DirectCast(GetCurrentWebDoc.getElementById("MakeAndModelSearch1_m_search"), mshtml.HTMLInputElementClass).click()
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  8. #168
    New Member
    Join Date
    Aug 2007
    Posts
    5

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Hi

    I have two problems which I'm trying to resolve and which I hope you can help:

    1. I'd like to pick up the ellement attibutes that the mouse is currently hovering over: name, id etc

    2. I have a test login page, which (I presume supports cookies) once I have logged in, the browser retains the information and automatically logs in when I visit the page. I would like to prevent this behaviour. (this is mainly for testing)

    You are very helpful but is there any source of information on this control from MS?

  9. #169
    New Member
    Join Date
    Sep 2007
    Posts
    3

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    I have read through the entire string and I saw a couple people ask how to use this with a web page that has frames. Has that been posted here or in another string yet.

  10. #170
    Addicted Member
    Join Date
    Aug 2006
    Posts
    160

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Hi
    i'm trying to fill in a textbox on a page for a login

    I've tried this code:

    WebBrowser1.Document.GetElementsByTagName("input").Item(22).SetAttribute("value", txtUser.text)

    but it says "Specified cast is not valid" on this line.

    how can I fix this?


    thanks to anyone who helps

    edit: btw, this is for the ebay login page, here

    https://signin.ebay.co.uk/ws/eBayISA...k/&_trksid=m37
    Last edited by 4xzer0; Sep 2nd, 2007 at 04:18 PM.

  11. #171
    Addicted Member
    Join Date
    Mar 2006
    Posts
    180

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    In my web browser when the page goes from secure https to http I get a dialog box which says "this page contains secure and non secure items etc etc"

    Is there anyway to disable this prompt somehow?

    Thanks

  12. #172

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,251

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Quote Originally Posted by MondeoST24
    In my web browser when the page goes from secure https to http I get a dialog box which says "this page contains secure and non secure items etc etc"

    Is there anyway to disable this prompt somehow?

    Thanks
    No. that prompt means that some items (usually pictures) are being pulled from an HTTP source and not an HTTPS source. This is actually a problem with the website not being done correctly versus a problem with the webbrowser.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  13. #173
    Addicted Member
    Join Date
    Aug 2006
    Posts
    160

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Kleinma can you help me please with the ebay login?
    I am using visual studio 2005..

  14. #174

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,251

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Quote Originally Posted by 4xzer0
    Kleinma can you help me please with the ebay login?
    I am using visual studio 2005..
    are you using the 2.0 webbrowser control from the toolbox? Or are you using the COM based control?
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  15. #175
    Addicted Member
    Join Date
    Aug 2006
    Posts
    160

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Quote Originally Posted by kleinma
    are you using the 2.0 webbrowser control from the toolbox? Or are you using the COM based control?
    yes i'm using the webbrowser 2.0 control from the toolbox..

    did you see what i tried earlier? (about 4 posts up from here)

  16. #176

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,251

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Quote Originally Posted by 4xzer0
    yes i'm using the webbrowser 2.0 control from the toolbox..

    did you see what i tried earlier? (about 4 posts up from here)

    seems to work fine for me using this code

    Code:
        Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
            WebBrowser1.Document.Forms("SignInForm").All("userid").SetAttribute("Value", "hello")
            WebBrowser1.Document.Forms("SignInForm").All("pass").SetAttribute("Value", "world")
            WebBrowser1.Document.Forms("SignInForm").InvokeMember("submit")
        End Sub
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  17. #177
    New Member
    Join Date
    Sep 2007
    Posts
    3

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    kleinma, your code has been very helpful to me - I've learned alot. The one problem I had was that the website I was testing with used frames, and I kept getting a null reference error. I finally managed to get it work with the frames by doing the following:

    Dim objDoc1 as mshtml.HTMLDocument
    Dim objWin1, objWin2 as mshtml.IHTMLWindow2
    Dim objFrame1 as mshtml.FramesCollection

    objDoc1 = AxWebBrowser1.Document
    objWin1 = objDoc1.parentWindow
    objFrame1 = objWin1.frames
    objWin2 = objFrame1.item(2) 'Was working with 3rd Frame
    objWin2.document.all.item("USERID").value = "Text"

    Thanks for all the effort you have put into this string - you have helped alot of us.

  18. #178
    Addicted Member
    Join Date
    Aug 2006
    Posts
    160

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Quote Originally Posted by kleinma
    seems to work fine for me using this code

    Code:
        Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
            WebBrowser1.Document.Forms("SignInForm").All("userid").SetAttribute("Value", "hello")
            WebBrowser1.Document.Forms("SignInForm").All("pass").SetAttribute("Value", "world")
            WebBrowser1.Document.Forms("SignInForm").InvokeMember("submit")
        End Sub
    Oh, thanks a lot kleinma !
    this code works great
    Last edited by 4xzer0; Sep 4th, 2007 at 12:39 PM.

  19. #179
    Addicted Member
    Join Date
    Mar 2006
    Posts
    180

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Kleinma,

    Do you know how to instantiate/initialize the ax web browser control manually?

    I want to create it from scratch in a seperate thread to the UI, I can create it and it appears on the form however when I call its navigate method I get this

    Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was unhandled

    Thanks

  20. #180

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,251

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Quote Originally Posted by tnooc
    kleinma, your code has been very helpful to me - I've learned alot. The one problem I had was that the website I was testing with used frames, and I kept getting a null reference error. I finally managed to get it work with the frames by doing the following:

    Dim objDoc1 as mshtml.HTMLDocument
    Dim objWin1, objWin2 as mshtml.IHTMLWindow2
    Dim objFrame1 as mshtml.FramesCollection

    objDoc1 = AxWebBrowser1.Document
    objWin1 = objDoc1.parentWindow
    objFrame1 = objWin1.frames
    objWin2 = objFrame1.item(2) 'Was working with 3rd Frame
    objWin2.document.all.item("USERID").value = "Text"

    Thanks for all the effort you have put into this string - you have helped alot of us.
    I know there are issues with frames and manipulating the DOM properly. I haven't really had time to dig in and try to get it working. Do you have a specific URL to reference?
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  21. #181

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,251

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Quote Originally Posted by MondeoST24
    Kleinma,

    Do you know how to instantiate/initialize the ax web browser control manually?

    I want to create it from scratch in a seperate thread to the UI, I can create it and it appears on the form however when I call its navigate method I get this

    Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was unhandled

    Thanks
    I will start off by asking why you would need to put it in a seperate thread? The control itself is actually multithreaded in that navigations and such are not held up by the windows app consuming the browser control unless your code tells it to via one of the exposed events/properties of the browser control.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  22. #182
    Lively Member
    Join Date
    Mar 2006
    Posts
    124

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Hi Kleinma, Great piece of code here. Has saved me soo much time filling in forms on webpages. Now I have a problem and was hoping maybe you can help. I posted on the VB.net forum but no answers and saw you have been posting back on this thread. So hopefully you can help me out.

    Here is my post.

    Again thanks for posting this code.

    http://vbforums.com/showthread.php?p...62#post2995362

  23. #183

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,251

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Quote Originally Posted by Mark Douglas
    Hi Kleinma, Great piece of code here. Has saved me soo much time filling in forms on webpages. Now I have a problem and was hoping maybe you can help. I posted on the VB.net forum but no answers and saw you have been posting back on this thread. So hopefully you can help me out.

    Here is my post.

    Again thanks for posting this code.

    http://vbforums.com/showthread.php?p...62#post2995362
    The problem has nothing to do with the table. The problem is the page you were trying to manipulate has more than one form. If you look through my sample code, the GetCurrentWebForm function has comments above it. I mention that the sample code assumes the page only has one form, as it grabs the first form on the page (index 0). Since the form you want to manipulate is actually the second form in the page, you need to grab that one instead.

    You can add this function to the existing GetCurrentWebForm() function (they will overload eachother)

    Code:
        Private Function GetCurrentWebForm(ByVal FormName As String) As mshtml.HTMLFormElement
            Try
                If GetCurrentWebDoc.forms.length > 0 Then
                    Return DirectCast(GetCurrentWebDoc.forms.item(FormName), mshtml.HTMLFormElement)
                Else
                    Return Nothing
                End If
            Catch ex As Exception
                Return Nothing
            End Try
        End Function
    It does the same thing as the one that takes no parameters, but this one takes one, allowing you to specify the name of the form you want. Your forms name was "mainform", so you can use code like this:

    Code:
            With GetCurrentWebForm("mainform")
                DirectCast(.item("address"), mshtml.HTMLInputElement).value = "Value Here"
            End With
    Which works fine.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  24. #184
    Addicted Member
    Join Date
    Mar 2006
    Posts
    180

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Quote Originally Posted by kleinma
    I will start off by asking why you would need to put it in a seperate thread? The control itself is actually multithreaded in that navigations and such are not held up by the windows app consuming the browser control unless your code tells it to via one of the exposed events/properties of the browser control.
    Hi Kleinma,

    The app I am building is for price comparison, it basically needs to connect to 7 sites, fill them in and then get information from the results page and present /format all the results to the user. The scraping of each site takes about 30 seconds, so I wanted to run them all concurrently using backgroundworkers if possible.

    What do you think, have I got the approach wrong?

    Thanks again.

  25. #185
    Lively Member
    Join Date
    Jun 2007
    Posts
    81

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Quote Originally Posted by kleinma
    sure.

    to get this setup you need to do the following

    1) create a new Windows Application in Visual Studio
    2) select "add reference" from the project menu, and under the .NET tab try to locate microsoft.mshtml (which is microsoft.mshtml.dll)

    If you don't see it there then try to search your compute rfor microsoft.mshtml.dll. if you don't have it at all, then you can download it from post #88 in this thread (it is also included in the download of the sample project in post #1)

    mshtml.dll is the HTML parsing engine. It is what allows you to parse and manipulate individual HTML elements in the browser control.

    So once you have that done its on to step 3

    3) right click in your toolbox (where all the controls are) and select "Choose Items" Then select the "COM components" tab when the dialog comes up.

    Scroll down and find "Microsoft Web Browser" and click the checkbox and then click OK. This will add the COM based webbrowser control to your toolbox so you can drag it to a form.

    That is all there is to it. From there you can use my example code to see how you actually do the manipulations of the webpage.
    Hi,

    Thanks for this info but when I get to step 2 microsoft.mshtml.dll does not appear under the .NEt tab but it is in my windows/system32 directory. How do I get it to appear under the .NET tab. I am using VB2005 Express, thanks.

  26. #186

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,251

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    lol, well read over what you quoted me saying one more time..

    I stated the following:
    If you don't see it there then try to search your compute rfor microsoft.mshtml.dll. if you don't have it at all, then you can download it from post #88 in this thread (it is also included in the download of the sample project in post #1)
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  27. #187
    New Member
    Join Date
    Aug 2007
    Posts
    5

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Hi Kleinma

    I have a problem with a login form: if I enter the text (username and password) manually - fine. If I cut and paste the same information into a standard browser- the site returns a "failed login". If I try to automate with the Browser control then its the same as cut and paste.

    Have you any thoughts please?

    I can post you the web page HTML off line if that helps.

  28. #188

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,251

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    I can't really help with that information. You would need to provide more and I will see if I can help or not.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  29. #189
    Lively Member
    Join Date
    Jun 2007
    Posts
    81

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Quote Originally Posted by kleinma
    lol, well read over what you quoted me saying one more time..

    I stated the following:
    I already have the microsoft.mshtml.dll in my windows/system32 directory but it does not appear under the .NET tab. Is there a missing step that makes it appear. Thanks.

  30. #190

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,251

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    there is also a "browse" tab. Use that instead of the .NET tab when setting the reference and browse the the system32 folder.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  31. #191
    Junior Member
    Join Date
    Oct 2007
    Posts
    18

    Thumbs up Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Quote Originally Posted by kleinma
    when you run into this type of situation, try to figure out what action you are trying to simulate versus the result you want (sometimes the opposite is true). In this case, you want to simulate clicking on an image. It just so happens that the result is submitting the form.

    Try this code to simulate clicking the image, which in turn should fire any code attached to that image.

    Code:
    DirectCast(GetCurrentWebDoc.images.item("ctl00$Main$postComment$postcommentImageButton"), mshtml.HTMLImg).click()
    if that name value doesn't work, try the ID instead ("ctl00_Main_postComment_postcommentImageButton")

    I do hope you are making some sort of "utility", and not anything that could be used maliciously to spam comments all over myspace.


    What a great resource this thread has been, one of very few on the internet for this subject matter. Specific to this issue, my company now has it's own myspace page and it's my job to work it. %-(

    I'm first seeing if it's feasible to do by generating this temporary test solution. I need to auto-comment anyone who sends us a comment or becomes our friend. Akin to this post, you showed how to click on an image, but I'm trying to fill in a textarea form field with your example. However, I'm running into problems. Here is the text area field data source I'm trying to automate similar to the poster above:

    Code:
    <textarea name="ctl00$cpMain$postComment$commentTextBox" rows="5" cols="40" id="ctl00_cpMain_postComment_commentTextBox" style="width:100%;"></textarea>
    I used your source project to try and autofill the textarea box but it's not working. My test program throws an exception stating "Object reference not set to an instance of an object") It keeps telling me that I need to declare a new object. I've tried both ID & Name of control and here is a sample code I'm trying:

    Code:
    Public Class BuiltInBrowser
    
        Private Sub BuiltInBrowser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            wB.Navigate("http://comment.myspace.com/index.cfm?fuseaction=user.viewProfile_commentForm&friendID=8")
    
        End Sub
    
        Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetText.Click
            SetTextareaText(txtMessage.Text)
        End Sub
    
        Private Sub SetTextareaText(ByVal Text As String)
            Try
                DirectCast(GetCurrentWebForm.item("ctl00cpMain$postComment$commentTextBox"), mshtml.HTMLTextAreaElement).value = Text
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
    
        End Sub
    
        Private Function GetCurrentWebDoc() As mshtml.HTMLDocument
            Try
                Return DirectCast(wb.Document, mshtml.HTMLDocument)
            Catch ex As Exception
                Return Nothing
            End Try
        End Function
    
        Private Function GetCurrentWebForm() As mshtml.HTMLFormElement
            Try
                If GetCurrentWebDoc.forms.length > 0 Then
                    Return DirectCast(GetCurrentWebDoc.forms.item(0), mshtml.HTMLFormElement)
                Else
                    Return Nothing
                End If
            Catch ex As Exception
                Return Nothing
            End Try
        End Function
    
       
    End Class

    Any help in this matter would be GREATLY appreciated!

  32. #192

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,251

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    OnlineNoob,

    The problem MAY be that the page you are trying to manipulate has more than one form on it.

    If you look at my code for GetCurrentWebForm, it checks to see if there is at least one form, and then returns that first form. However the textarea you are looking to manipulate may very well be in a second, third, or Nth form on the webpage. So you may have to modify the code to return a reference to a different form in order to manipulate the textarea on it. I believe this is mentioned in the comments in my code for that routine.

    My example only grabs the first form because the example HTML page I included with the sample project only has one form, and is after all, just an example.

    Check that out first, then post back with how you make out.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  33. #193
    Junior Member
    Join Date
    Oct 2007
    Posts
    18

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    hi Kleinma, thanks for your response. I added a parameter to the code to make it like the following:

    Code:
    Public Class BuiltInBrowser
    
        Private Sub BuiltInBrowser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            wB.Navigate("http://comment.myspace.com/index.cfm?fuseaction=user.viewProfile_commentForm&friendID=8")
    
        End Sub
    
        Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetText.Click
            SetTextareaText(txtMessage.Text)
        End Sub
    
        Private Sub SetTextareaText(ByVal Text As String)
            Try
                DirectCast(GetCurrentWebForm(2).item("ctl00_cpMain_postComment_commentTextBox"), mshtml.HTMLTextAreaElement).value = Text
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
    
        End Sub
    
        Private Function GetCurrentWebDoc() As mshtml.HTMLDocument
            Try
                Return DirectCast(wb.Document, mshtml.HTMLDocument)
            Catch ex As Exception
                Return Nothing
            End Try
        End Function
    
        Private Function GetCurrentWebForm(ByVal intFormNumber As Integer) As mshtml.HTMLFormElement
            Try
                If GetCurrentWebDoc.forms.length > 0 Then
                    Return DirectCast(GetCurrentWebDoc.forms.item(intFormNumber), mshtml.HTMLFormElement)
                Else
                    Return Nothing
                End If
            Catch ex As Exception
                Return Nothing
            End Try
        End Function
    
    End Class
    Amazingly enough, i only added the parameter for the function you created and set the form n8umber to the proper number and it walaa, it worked. However, i had to also change the textarea selected to use the ID of the contyrol because the name of the control didn't work. Other than that, the code workds great now. Thank you for your patience!!!!!

  34. #194

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,251

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    glad to hear you got it working.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  35. #195
    New Member
    Join Date
    Aug 2007
    Posts
    5

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Hi Thanks for your previous help.

    I'm not sure if I'm doing something silly. VS2005, I am trying to use SendKeys (and this was refered to earlier in this thread) and the control does not seem to programattically accept focus. If I click on it and type <Ctrl +a> then the page / frame is selected. Tabstop = true. The standard browser control seems to accept focus, but not the ax one. If I code:

    browserCtl.focus
    ...sendkeys("{^}a")

    No joy

    Any thoughts please.

  36. #196

    Thread Starter
    Moderator.NET kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,251

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    ian,

    check your PMs, but sendkeys is absolutely NOT the way to go to automate things in a browser. There are way too many hiccups and chances for error.
    Using VS.NET 2013/.NET 2.0 through 4.5 * Please mark you thread resolved using the Thread Tools above
    PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!!
    * If you found a post useful then please Rate it! * DO NOT PM ME WITH LINKS TO YOUR THREADS FOR ANSWERS PLEASE!

    Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup
    ZerosAndTheOne.com
    -=Matt=-

  37. #197
    Addicted Member
    Join Date
    Nov 2006
    Location
    Minnesota
    Posts
    235

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    This was a fantastic help and very interesting to look through. Really enjoyed. Thanks kleinma.

    Incidentally, this is what i ended up coding to access frames.

    Code:
     Private Function GetWebFrameObject(ByVal PassDocumentObject As Object) As mshtml.HTMLWindow2
            Try
                Return DirectCast(PassDocumentObject, mshtml.HTMLWindow2)
            Catch ex As Exception
                Return Nothing
            End Try
        End Function
    
        Private Function getwebform(ByVal PassDocumentObject As mshtml.HTMLDocument) As mshtml.HTMLFormElement
            Try
                Return DirectCast(PassDocumentObject.forms.item(0), mshtml.HTMLFormElement)
    
            Catch ex As Exception
                Return Nothing
            End Try
    
        End Function
    
        Private Sub SetFrameTextBox(ByVal FrameNumber As Integer, ByVal ValueToSendToBox As String, ByVal FieldToFill As String)
            DirectCast(getwebform(GetWebFrameObject(GetCurrentWebDoc().frames.item(FrameNumber)).document).item(FieldToFill, 0), mshtml.HTMLInputElement).value = ValueToSendToBox
        End Sub
    
        Private Sub clicksubmitbuttonframes(ByVal FrameNumber As Integer, ByVal FieldToFill As String)
            DirectCast(getwebform(GetWebFrameObject(GetCurrentWebDoc().frames.item(FrameNumber)).document).item(FieldToFill, 0), mshtml.HTMLButtonElement).click()
        End Sub
    The only thing that i didn't like about how I did this was I needed to know the exact frame index number.

  38. #198
    Member
    Join Date
    Jul 2007
    Location
    Silly Clone Valley CA
    Posts
    47

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Using your example code I've been able to do about 80% of a project I needed to create for work. But I have one last item to figure out.

    The page has 4 drop down menus on it, each with about 20 or more items. I need to programatically search for a specific word and choose the drop down item that matches in each one. How would I do that? Here is what I've got so far:

    Code:
        Private Sub btnComboFill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnComboFill.Click
    
            Dim MyHTMLCombo As mshtml.HTMLSelectElement = DirectCast(GetCurrentWebForm.item("ctl00_ManagementMain_FirmwareUserControl_FirmwareFilename"), mshtml.HTMLSelectElement)
    
            Dim i As Integer
            For i = 0 To MyHTMLCombo.size
                If MyHTMLCombo.value.Contains(myfirmware) Then
                    MsgBox("I found it")
                End If
            Next
    My Languages: English, VB 2005, Perl
    My Hobbies: Code, Photoshop, Skateboarding, Video Games, Flying, Cars(modification), Airbrushing, Electronic music DJing, and production.

  39. #199
    Member
    Join Date
    Jul 2007
    Location
    Silly Clone Valley CA
    Posts
    47

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Quote Originally Posted by kleinma
    you need to use the DocumentComplete event of the webbrowser control. This event fires when a page has fully loaded. So when you do the first postback, the DocumentComplete event will fire when the page has posted back and reloaded in the browser.
    I'm not sure how to use an event to handle this. For instance, say I need to navigate through 3 pages and I want it to do this all using 1 user event. How can I handle this?

    1 first page load
    Documentcomplete fires and I put in the second page there
    second page loads
    Now how do I get to the third page?
    My Languages: English, VB 2005, Perl
    My Hobbies: Code, Photoshop, Skateboarding, Video Games, Flying, Cars(modification), Airbrushing, Electronic music DJing, and production.

  40. #200
    Member
    Join Date
    Jul 2007
    Location
    Silly Clone Valley CA
    Posts
    47

    Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control

    Nevermind on that second question, what I did was this (in pseudo code):

    dim 1,2 as boolean = false

    form load event
    timer1.enabled

    timer1 event
    wb.navigate("webpage1")
    1 = true
    timer1.enabled = false

    wb DocumentComplete event

    if 2 = true then
    wb.navigate("webpage3")
    2 = false
    end if

    if 1 = true then
    wb.navigate("webpage2")
    1 = false
    2 = true
    end if

    Thanks! although I still need help figuring out how to select those drop down items. I can use your code to figure out the index and name, but I can't select it using a word contained in an item.
    My Languages: English, VB 2005, Perl
    My Hobbies: Code, Photoshop, Skateboarding, Video Games, Flying, Cars(modification), Airbrushing, Electronic music DJing, and production.

Page 5 of 14 FirstFirst ... 2345678 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.