.NET General

Moderators: None (Apply to moderate this forum)
Number of threads: 749
Number of posts: 1301

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help on Invoking Click Event Posted by Isip2 on 24 Apr 2009 at 10:00 PM
Hi!

I am currently doing a project that involves automated logging-in on web accounts. I used the webBrowser control for this purpose and so far everything is working fine.

However, the method I use is: webBrowser1.Document.GetElementById("btnSubmitURL").InvokeMember("click");

The problem comes in when the button elements do not have name or id properties. Is there a way to invoke the click event without knowing the name or id of the button element?

The only other method I know is GetElementFromPoint(), but it would be good if there is another way since this method requires knowledge on the coordinates of the button.

Thanks everyone.
Report
Re: Help on Invoking Click Event Posted by Psightoplazm on 25 Apr 2009 at 8:24 AM
Well you obviously can't tell something to click itself without knowing who to tell - but what the WebBrowser does do for you is it breaks everything down into a complete DOM hierachy. If you can identify anything about the structure of the page - like is it inside a table that has a particular name or whatever, then you can find your control.

I think what you are looking for is just being able to submit a "Form" block element - and you can actually do that directly off of the form. You can also search for the only "submit" inside the child hierarchy the form.

            var m = new WebBrowser();
            m.Navigate("www.somewhere.com");
            m.DocumentCompleted +=
                delegate
                    {
                        // Grab the form and submit it
                        var form = m.Document.GetElementById("MyForm");
                        form.InvokeMember("submit");

                        // or you can find the submit button inside the form...
                        var controls = form.GetElementsByTagName("input");
                        foreach (var c in controls.Cast<HtmlElement>())
                            if (c.GetAttribute("type") == "submit")
                                c.InvokeMember("click");
                    };



></\/~Psightoplasm`~
Report
Re: Help on Invoking Click Event Posted by Isip2 on 25 Apr 2009 at 7:50 PM
Wow great help.
I better start thinking some more so I won't miss solutions like this.

Thanks again Psightoplazm, I think this should work.
Report
Re: Help on Invoking Click Event Posted by Isip2 on 26 Apr 2009 at 1:44 AM
Hi!

I have a hopefully more difficult problem at hand. Is there a way to retrieve a dynamic image, say a banner, directly from the webBrowser control? It should be retrieved without making an additional web request since an additional request would change the image.

For a more specific example, how can I load an image shown in the WebBrowser control into a PictureBox? The use of the ImageLocation property will not work since it will request the image from the server.

Any idea?

Thanks.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.