how to fill in html textbox from windows application

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jimbo

    how to fill in html textbox from windows application

    Hey

    I would like to do the following from a windows application:

    1. Open a browser and navigate to a URL.
    2. When i am at the correct URL in my browser window, i want to fill in data
    in the html textboxes on that page from my windows application.
    3. When thats done i want to press a button.
    4. last i want to navigate to another URL.

    Well, it seems like i did the first issue perfectly (i think), but working
    on issue number 2 is killing me. How can i fill in my user input
    automatically to my web browser from my windows application?

    Ok, heres what i got so far:


    SHDocVw.ShellWi ndows SWs = new SHDocVw.ShellWi ndows();
    SHDocVw.Interne tExplorer IExplorer = new
    SHDocVw.Interne tExplorer();

    IExplorer.Visib le = true;
    IExplorer.Navig ate(http://MyURL.asp, ref o, ref o, ref o, ref
    o);

    int counter = SWs.Count;

    foreach (SHDocVw.Intern etExplorer ie in SWs)
    {
    if (ie.LocationURL .ToString() == http://MyURL/SubPage.asp)
    {
    IHTMLDocument2 document = (IHTMLDocument2 )ie.Document;
    MessageBox.Show (document.all.t ags("navn").ToS tring());
    //Gives me System.__ComObj ect???

    //So far so good
    //The following is simply just not working. Maybe im doing it all wrong??

    HTMLTextElement navn =
    (HTMLTextElemen t)document.all. tags("navn");
    navn.innerText = "HEJ";

    }
    }

    Anyone?

    --


    Jimmy


  • Kevin Yu [MSFT]

    #2
    RE: how to fill in html textbox from windows application

    Hi Jimmy,

    First of all, I would like to confirm my understanding of your issue. From
    your description, I understand that you need to put everything you input
    from a Windows Form app into a web page and navigate to that page. If there
    is any misunderstandin g, please feel free to let me know.

    Based on my experience, the best practice is to achieve this is to use 2
    apps. One is winform app as currently used, the other is a web app which
    converts the input data to an html page.

    We can navigate to the web app's URL and pass the values of the winform
    controls as query string. The web app gets the query string and display the
    HTML page with values in the web browser.

    HTH.

    Kevin Yu
    =======
    "This posting is provided "AS IS" with no warranties, and confers no
    rights."

    Comment

    • Jimbo

      #3
      Re: how to fill in html textbox from windows application

      "Kevin Yu [MSFT]" <v-kevy@online.mic rosoft.com> skrev i en meddelelse
      news:Jfwo2P4eFH A.4300@TK2MSFTN GXA01.phx.gbl.. .[color=blue]
      > Hi Jimmy,
      >
      > First of all, I would like to confirm my understanding of your issue. From
      > your description, I understand that you need to put everything you input
      > from a Windows Form app into a web page and navigate to that page. If
      > there
      > is any misunderstandin g, please feel free to let me know.[/color]

      I think you got it, but im gonna describe the steps included:

      1. The win app should open a browser and navigate to a specific sites
      loginURL (its my own web pages).
      2. input the data for the username and password on the web pages form fields
      3. press the login button on the web page
      4. after a successfull login it should navigate to a specific web page
      [color=blue]
      > Based on my experience, the best practice is to achieve this is to use 2
      > apps. One is winform app as currently used, the other is a web app which
      > converts the input data to an html page.[/color]

      That would require me to do some web development. I was actually trying to
      avoid this, as many users are using these pages, and i wouldnt wanna change
      anything on them.
      [color=blue]
      > We can navigate to the web app's URL and pass the values of the winform
      > controls as query string. The web app gets the query string and display
      > the
      > HTML page with values in the web browser.[/color]

      I can see your point, but isnt it possible to input the data directly into
      the fields on the web page from my win app.

      If not, how du i post data from a win app to a web site?

      thanks


      Jimmy


      Comment

      • Jimbo

        #4
        Re: how to fill in html textbox from windows application

        "Jimbo" <jimbo@nospam.n ospam> skrev i en meddelelse
        news:%23QhtvKye FHA.3620@TK2MSF TNGP09.phx.gbl. ..[color=blue]
        > Hey
        >
        > I would like to do the following from a windows application:
        >
        > 1. Open a browser and navigate to a URL.
        > 2. When i am at the correct URL in my browser window, i want to fill in
        > data in the html textboxes on that page from my windows application.
        > 3. When thats done i want to press a button.
        > 4. last i want to navigate to another URL.[/color]

        Hey

        Ok figured out point 2.

        My probblem is now point 3. Seems like nothing that i do is working. How can
        you simulate a click on a button (input type=image) from your win app.?


        Jimmy


        Comment

        • sommerbeast@20min.ch

          #5
          Re: how to fill in html textbox from windows application

          have a look at http://curl.haxx.se/

          Comment

          • Jimbo

            #6
            Re: how to fill in html textbox from windows application

            "Jimbo" <jimbo@nospam.n ospam> skrev i en meddelelse
            news:%23QhtvKye FHA.3620@TK2MSF TNGP09.phx.gbl. ..[color=blue]
            > Hey
            >
            > I would like to do the following from a windows application:
            >
            > 1. Open a browser and navigate to a URL.
            > 2. When i am at the correct URL in my browser window, i want to fill in
            > data in the html textboxes on that page from my windows application.
            > 3. When thats done i want to press a button.
            > 4. last i want to navigate to another URL.[/color]

            Ok, seems like i have worked out all 4 points. Now i would like to create a
            5th point.

            5. When i have reached the URL at point 4, i would like to check once in a
            while (say every 5 minutes), if the page is still running. If its not, i
            will start all over. If it is running everythings fine. I use the objects in
            SHDocVw.dll and mshtml.dll, but no matter what i do it seems like i cannot
            check for this. If i get the standard error message in my Internet Explorer
            window "the page could not be found" its like i still have access to the
            full page, even though its not there anymore. I have access to all the
            fields, the title and everything. So it seems like i cannot tell if the page
            is running or not.
            Anyone who can figure out how to check wether the page is running or not
            through a windows application?

            I would really apprieciate this.


            Jimmy


            Comment

            • Kevin Yu [MSFT]

              #7
              Re: how to fill in html textbox from windows application

              Hi Jimmy,

              Do you mean that you need to check if the IExplorer is still displaying? If
              so, the only thing we can do is to check the LocationURL property of
              IExplorer.

              Kevin Yu
              =======
              "This posting is provided "AS IS" with no warranties, and confers no
              rights."

              Comment

              • Jimbo

                #8
                Re: how to fill in html textbox from windows application

                "Kevin Yu [MSFT]" <v-kevy@online.mic rosoft.com> skrev i en meddelelse
                news:NLUkV8EfFH A.944@TK2MSFTNG XA01.phx.gbl...[color=blue]
                > Hi Jimmy,
                >
                > Do you mean that you need to check if the IExplorer is still displaying?
                > If
                > so, the only thing we can do is to check the LocationURL property of
                > IExplorer.[/color]

                Yep, if the IExplorer is still displaying the correct page. Say the page im
                on is http://Mywebsite/app.asp. When i check the LocationURL i should get
                that address. I do, but heres the thing: When i disconnect my network
                connection, and do a refresh on the page, or a navigate to the page for that
                matter, Whats displayed in my browser window is "Page is not found". Then i
                check the LocationURL property and it still says http://Mywebsite/app.asp.
                Weird right?

                Any suggestions?


                Jimmy


                Comment

                • Kevin Yu [MSFT]

                  #9
                  Re: how to fill in html textbox from windows application

                  Hi Jimbo,

                  This is the designed behavior of IE. Yes, although checking the LocationURL
                  property is not reliable, this is the only way to check if the page is
                  displaying as far as I know. You can also check the BeforeNavigate2 and
                  TitleChange event to make the checking more reliable. But there is no
                  absolutely reliable way to check for this.

                  Kevin Yu
                  =======
                  "This posting is provided "AS IS" with no warranties, and confers no
                  rights."

                  Comment

                  • Jimbo

                    #10
                    Re: how to fill in html textbox from windows application

                    "Kevin Yu [MSFT]" <v-kevy@online.mic rosoft.com> skrev i en meddelelse
                    news:anCq2zRfFH A.1336@TK2MSFTN GXA01.phx.gbl.. .[color=blue]
                    > Hi Jimbo,
                    >
                    > This is the designed behavior of IE. Yes, although checking the
                    > LocationURL
                    > property is not reliable, this is the only way to check if the page is
                    > displaying as far as I know. You can also check the BeforeNavigate2 and
                    > TitleChange event to make the checking more reliable. But there is no
                    > absolutely reliable way to check for this.[/color]

                    Thanks Kevin

                    Instead i now try to get some values out of some fields at the correct HTML
                    page. if the fields is not there its gonna cause an exception wich i catch.
                    That seems to work altough im not glad that i couldnt do it the other way
                    around.

                    Thanks for your help :)


                    Jimmy


                    Comment

                    • Kevin Yu [MSFT]

                      #11
                      Re: how to fill in html textbox from windows application

                      Hi Jimmy,

                      Yes, I agree with you that it's a workaround. But the con is that we have
                      to modify the code when the format of HTML page changes. Anyway, I'm glad
                      to hear that you have had this resolved.

                      Thanks for sharing your experience with all the people here. If you have
                      any questions, please feel free to post them in the community.

                      Kevin Yu
                      =======
                      "This posting is provided "AS IS" with no warranties, and confers no
                      rights."

                      Comment

                      Working...