Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Programmatically pressing a webBroswer button

Programmatically pressing a webBroswer button

Scheduled Pinned Locked Moved C#
csharpcssvisual-studioquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Martin23
    wrote on last edited by
    #1

    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

    J E C 3 Replies Last reply
    0
    • M Martin23

      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

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • J Judah Gabriel 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

        M Offline
        M Offline
        Martin23
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • M Martin23

          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

          E Offline
          E Offline
          emran834
          wrote on last edited by
          #4

          Hello, Can you show me a snippet to post form data from Windows form to a URL thru a webbrowser control so that the post result will be returned to that webbrowser. Thanks

          1 Reply Last reply
          0
          • M Martin23

            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

            C Offline
            C Offline
            cweeks78681
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups