Page view counter

Webbrowser click on button

Last post 10-01-2008 4:03 AM by Lance Zhang - MSFT. 10 replies.

Sort Posts:

  • Webbrowser click on button

    09-27-2008, 4:15 PM
    • Loading...
    • pascallj
    • Joined on 09-27-2008, 8:08 PM
    • Posts 5
    • Points 0

     Hello everybody, I am new here on this forum because I have a question.

    I make a project with a webbrowser. I want to know how you can click on a button on a website automatic.
    I've got already this in a button:

     

    1            Browser.Document.GetElementById("login_nickname").InnerText = Username.Text
    2 Browser.Document.GetElementById("login_password").InnerText = Password.Text
     

    This will fill in a textfield when you press on that button. But how can you automatic click on a button from a website.

    Greetz, Pascal

    O, ehm I am Dutch and just 13 years old so my english is.. Let's say not good....

    I am Dutch and 13 years old. So my English is not good. Or.. Bad.
  • Re: Webbrowser click on button

    09-27-2008, 7:09 PM
    • Loading...
    • anas
    • Joined on 09-21-2006, 4:31 AM
    • Ramallah, Palestine
    • Posts 6,114
    • Points 48,391
    • Moderator

     If we assumed that the button id is "Button1" then you can programatically click it using this JavaScript code :

                var btn = document.getElementById('<%= Button1.ClientId %>');
                btn.click();

    Regards,

    Anas Ghanem.


    Note:Please Don't hesitate to click "Alert Moderators" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

  • Re: Webbrowser click on button

    09-28-2008, 7:30 AM
    • Loading...
    • pascallj
    • Joined on 09-27-2008, 8:08 PM
    • Posts 5
    • Points 0

     Sorry but is that code for visual basic 2008? Because I've got 7 errors. And the name from the button on the webpage is "submit".

    Pascal

    I am Dutch and 13 years old. So my English is not good. Or.. Bad.
  • Re: Webbrowser click on button

    09-28-2008, 7:47 AM
    • Loading...
    • NC01
    • Joined on 08-26-2005, 3:33 PM
    • Posts 13,275
    • Points 71,391
    • TrustedFriends-MVPs

    Are you building a web page (using ASP.NET)? If so, this syntax won't work:
         Browser.Document.GetElementById("login_nickname").InnerText = Username.Text

    This should be:
         <script type="text/javascript">
         <!--
         document.getElementById('login_nickname').innerHTML = 'some new value';     // .innerText will work on some browsers
         // -->
         </script>

    Note the casing as JavaScript is case-sensitive.

    If you are not building a web page (using ASP.NET), then I am afraid that you are on the wrong forum as this is an ASP.NET forum, client-side web development in particular. We can help with some WinForms questions, but we are generally not experts. Try: http://windowsclient.net/forums/

    NC...

  • Re: Webbrowser click on button

    09-28-2008, 8:11 AM
    Answer
    • Loading...
    • anas
    • Joined on 09-21-2006, 4:31 AM
    • Ramallah, Palestine
    • Posts 6,114
    • Points 48,391
    • Moderator

    I think you are working with web browser control which is for windows application,

    I think in this case you need to use InvokeMember method ,

    if the button id is "Submit" , then you may need to use this code :

     

    Browser.Document.GetElementById("Submit").InvokeMember("click")

    Regards,

    Anas Ghanem.


    Note:Please Don't hesitate to click "Alert Moderators" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

  • Re: Webbrowser click on button

    09-28-2008, 9:25 AM
    • Loading...
    • pascallj
    • Joined on 09-27-2008, 8:08 PM
    • Posts 5
    • Points 0
    Oh yes thanks! That's where i'm looking for. It's now working, Thanks! But how do you now all that codes? I want to learn programming self and not by copy/paste. If you followed a cursus?
    I am Dutch and 13 years old. So my English is not good. Or.. Bad.
  • Re: Webbrowser click on button

    09-28-2008, 9:28 AM
    • Loading...
    • pascallj
    • Joined on 09-27-2008, 8:08 PM
    • Posts 5
    • Points 0

    NC01:

    Are you building a web page (using ASP.NET)? If so, this syntax won't work:
         Browser.Document.GetElementById("login_nickname").InnerText = Username.Text

    This should be:
         <script type="text/javascript">
         <!--
         document.getElementById('login_nickname').innerHTML = 'some new value';     // .innerText will work on some browsers
         // -->
         </script>

    Note the casing as JavaScript is case-sensitive.

    If you are not building a web page (using ASP.NET), then I am afraid that you are on the wrong forum as this is an ASP.NET forum, client-side web development in particular. We can help with some WinForms questions, but we are generally not experts. Try: http://windowsclient.net/forums/

    NC...

    O sorry I posted my topic in the visual basic 2008 section but my english is very bad so I think they moved it


    I am Dutch and 13 years old. So my English is not good. Or.. Bad.
  • Re: Webbrowser click on button

    09-28-2008, 9:34 AM
    • Loading...
    • NC01
    • Joined on 08-26-2005, 3:33 PM
    • Posts 13,275
    • Points 71,391
    • TrustedFriends-MVPs

    This entire site in an ASP.NET site, in other words, web page/application development site. The forum masters probably thought that it was a client-side post since it had document.getElementById in the post. You also might try Googling for what you want to learn, if you can learn from source code. Google is a tremendous resource for persons just starting out.

    NC...

     

  • Re: Webbrowser click on button

    09-28-2008, 9:37 AM
    • Loading...
    • pascallj
    • Joined on 09-27-2008, 8:08 PM
    • Posts 5
    • Points 0

     

    NC01:

    This entire site in an ASP.NET site, in other words, web page/application development site. The forum masters probably thought that it was a client-side post since it had document.getElementById in the post. You also might try Googling for what you want to learn, if you can learn from source code. Google is a tremendous resource for persons just starting out.

    NC...

     

    Yes I searched on Google. But I can't find the answer on my problem.

    I am Dutch and 13 years old. So my English is not good. Or.. Bad.
  • Re: Webbrowser click on button

    09-29-2008, 7:03 AM
    Answer
    • Loading...
    • NC01
    • Joined on 08-26-2005, 3:33 PM
    • Posts 13,275
    • Points 71,391
    • TrustedFriends-MVPs

    Did you try searching on Web Browser Control? http://www.google.com/search?hl=en&q=Web+Browser+Control&btnG=Google+Search&aq=f&oq=

    NC...

     

  • Re: Webbrowser click on button

    10-01-2008, 4:03 AM
    Answer
    Hi pascallj
     
    For the question about WebBrowser control of Windows Form application, you might post it on the following forum:
     
    Windows Forms General
    Discuss client application development using Windows Forms controls and features.
    http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=8&SiteID=1
     
    Thanks.

     

    Lance Zhang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (11 items)