Click a button on a web page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • emibt08
    New Member
    • Oct 2008
    • 25

    Click a button on a web page

    Hi. I am trying to make a simple C# WinForms app to get some data from a web site. It all works well until i got to a site where i can not directly go to the page i want. So, when i request the url (whether in C# or in a browser) i get redirected to a disclaimer page where i should click "I accept" to get in. And once i do, it doesn't redirect me to the url i previously entered, but the home page instead. So, i am looking for a way to press the button in code and go to the proper page all day long with no luck. And yes... i did google for an answer, but somehow i can't make heads or tails out of it. I know how to do POST with HttpWebRequest, but i guess i am missing something.
    Here is the page i want to get:

    http://pdonline.brisba ne.qld.gov.au/masterview/modules/applicationmast er/default.aspx?pa ge=wrapper&key= A001617250

    When i point to that url, i get his one:

    http://pdonline.brisba ne.qld.gov.au/masterview/masterplan/enquirer/default.aspx?pa ge=disclaimer

    where "I accept" button is.

    Thanks for any help in advance. Please let me know if you need more details.

    Cheers
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Originally posted by emibt08
    Hi. I am trying to make a simple C# WinForms app to get some data from a web site. It all works well until i got to a site where i can not directly go to the page i want. So, when i request the url (whether in C# or in a browser) i get redirected to a disclaimer page where i should click "I accept" to get in. And once i do, it doesn't redirect me to the url i previously entered, but the home page instead. So, i am looking for a way to press the button in code and go to the proper page all day long with no luck. And yes... i did google for an answer, but somehow i can't make heads or tails out of it. I know how to do POST with HttpWebRequest, but i guess i am missing something.
    Here is the page i want to get:

    http://pdonline.brisba ne.qld.gov.au/masterview/modules/applicationmast er/default.aspx?pa ge=wrapper&key= A001617250

    When i point to that url, i get his one:

    http://pdonline.brisba ne.qld.gov.au/masterview/masterplan/enquirer/default.aspx?pa ge=disclaimer

    where "I accept" button is.

    Thanks for any help in advance. Please let me know if you need more details.

    Cheers
    Hello fellow Queenslander!

    This is a dodgy work around, mate... but dodgy is better than nothin'.

    You could loop through the controls, find the one of type Button with .Text of "I Accept", move the mouse location to the to the middle of the button (Button.Locatio n.X + button.width/2, Button.Location .Y + button.height/2) then click the left mouse button programmaticaly .

    This example should help

    Comment

    • emibt08
      New Member
      • Oct 2008
      • 25

      #3
      Thanks for the reply tlhintoq.
      Well, the problem is that i am getting the html programmaticall y through WebRequest, so i really don't have a physical button to click on. Although i could use a WebBrowser control and invoke the Click method, i'd rather don't, since it will be just a temp patch, with a hidden control.
      So, i am getting the html and i did look for a submit input control, which i can find, but i think i need a way to construct a POST method and send it back... and that's where the trouble comes. I have tried using Fiddler to help me construct the data that i will post with no luck. I was also wondering if i should post back the __VIEWSTATE value.

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        You should postback exactly what the browser would postback. Which probably having to parse certain values out of the disclaimer page as well.
        Also, if it is not set for you automatically with the HttpWebRequest object, be sure to add the Session header line to make sure the server remembers who you are

        Comment

        • emibt08
          New Member
          • Oct 2008
          • 25

          #5
          Hi. With a little delay, i want to thank Plater for the suggestion. That was what i needed. Once i post back the session header, it all worked.

          Cheers

          Comment

          • amirghaffarie1362
            New Member
            • Jan 2009
            • 19

            #6
            what u mean "post back the session header" could u send me th sample code ????

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              There's the ASP.NET_Session Id cookie that needs to get sent back and forth
              Cookie: ASP.NET_Session Id=eljyrbah1bfw 5245z0altaf3
              Which means you have to look at the servers response to get the correct value for it, and send it with all your requests

              Comment

              • amirghaffarie1362
                New Member
                • Jan 2009
                • 19

                #8
                i see , as u r working on this , i had question befor i asked in this forum , unfortunetly nobody send me any reply , i try to get the source off each page of one web site but in that website they use linkbutton and with link button should go throw __dopostback , i try to send the form post with __evenargument and __eventtarget but it dosnt work , if u have any exprine about this ??? please send me reply
                regards

                Comment

                Working...