how to fill in html textbox from windows application

J

Jimbo

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.ShellWindows SWs = new SHDocVw.ShellWindows();
SHDocVw.InternetExplorer IExplorer = new
SHDocVw.InternetExplorer();

IExplorer.Visible = true;
IExplorer.Navigate(http://MyURL.asp, ref o, ref o, ref o, ref
o);

int counter = SWs.Count;

foreach (SHDocVw.InternetExplorer ie in SWs)
{
if (ie.LocationURL.ToString() == http://MyURL/SubPage.asp)
{
IHTMLDocument2 document = (IHTMLDocument2)ie.Document;
MessageBox.Show(document.all.tags("navn").ToString());
//Gives me System.__ComObject???

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

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

}
}

Anyone?
 
K

Kevin Yu [MSFT]

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 misunderstanding, 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."
 
J

Jimbo

Kevin Yu said:
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 misunderstanding, please feel free to let me know.

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
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.

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.
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.

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
 
J

Jimbo

Jimbo said:
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.

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
 
J

Jimbo

Jimbo said:
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.

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
 
K

Kevin Yu [MSFT]

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."
 
J

Jimbo

Kevin Yu said:
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.

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
 
K

Kevin Yu [MSFT]

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."
 
J

Jimbo

Kevin Yu said:
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.

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
 
K

Kevin Yu [MSFT]

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."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top