Programmatically pressing a webBroswer button
-
Hi guys, I have a program (in Visual studio 2005) that interacts with a webBrowser component, it needs to press buttons on webpages in that webBrowser, so far I have done this by focusing on the button then programmatically pressing "enter" as follows; webBrowser1.Document.GetElementById("button1").Focus(); SendKeys.Send("{ENTER}"); This works, but is less than satisfactory, because if the user starts using a different application it fires the "enter" key in the other application. This can mostly be avoided by checking my application has the user focus, but then if it doesn't have the user focus the "enter" is never fired. Is there a better way of programmatically pressing a button on the webpage? thanks a lot Martin
-
Hi guys, I have a program (in Visual studio 2005) that interacts with a webBrowser component, it needs to press buttons on webpages in that webBrowser, so far I have done this by focusing on the button then programmatically pressing "enter" as follows; webBrowser1.Document.GetElementById("button1").Focus(); SendKeys.Send("{ENTER}"); This works, but is less than satisfactory, because if the user starts using a different application it fires the "enter" key in the other application. This can mostly be avoided by checking my application has the user focus, but then if it doesn't have the user focus the "enter" is never fired. Is there a better way of programmatically pressing a button on the webpage? thanks a lot Martin
You could figure out what the button is doing from the Javascript and just call that javascript function directly. I guess the real question is, what are you really trying to do?
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Connor's Christmas Spectacular! Judah Himango
-
You could figure out what the button is doing from the Javascript and just call that javascript function directly. I guess the real question is, what are you really trying to do?
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Connor's Christmas Spectacular! Judah Himango
I am making a program to help with editing Wikipedia (you know, the free encylopedia, see http://en.wikipedia.org/wiki/Main\_Page). I can get and change the text in the textboxes, but I need to be able to press the "Save page" button when done. For an example of a webpage I am trying to press a button on see http://en.wikipedia.org/w/index.php?title=C\_Sharp&action=edit hope that explains it a bit more. thanks
-
Hi guys, I have a program (in Visual studio 2005) that interacts with a webBrowser component, it needs to press buttons on webpages in that webBrowser, so far I have done this by focusing on the button then programmatically pressing "enter" as follows; webBrowser1.Document.GetElementById("button1").Focus(); SendKeys.Send("{ENTER}"); This works, but is less than satisfactory, because if the user starts using a different application it fires the "enter" key in the other application. This can mostly be avoided by checking my application has the user focus, but then if it doesn't have the user focus the "enter" is never fired. Is there a better way of programmatically pressing a button on the webpage? thanks a lot Martin
-
Hi guys, I have a program (in Visual studio 2005) that interacts with a webBrowser component, it needs to press buttons on webpages in that webBrowser, so far I have done this by focusing on the button then programmatically pressing "enter" as follows; webBrowser1.Document.GetElementById("button1").Focus(); SendKeys.Send("{ENTER}"); This works, but is less than satisfactory, because if the user starts using a different application it fires the "enter" key in the other application. This can mostly be avoided by checking my application has the user focus, but then if it doesn't have the user focus the "enter" is never fired. Is there a better way of programmatically pressing a button on the webpage? thanks a lot Martin
I don't have access to my code at the moment but I have successfully done this by navigating to the button's HtmlElement object in the document and then invoking the InvokeMember() method: HtmlElement elt = webbrowser1.Document.GetElementsByTagName("INPUT")[0]; elt.InvokeMember("Click"); Now, that's rough approximation. You may have to make to changes to get it to compile. But you get the idea. -- modified at 17:15 Wednesday 26th April, 2006