c# - Open a web page and fill in text press a button


How I can use C# to do the following:

1. Open a web page in IE.
2. Put some text in an input field (form).
3. Press a button on this form.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

do you have control over the web page you wish to open ?
for if you don't your looking at a lot of effort to fill in text boxes as you don't know what they are named in someone else's code
whorsfallAuthor Commented:

No I don't have contol over the web site. However it is static on our intranet in which the names of the controls stay the same,

Thanks Ward
okay there are a few ways to do this..
the first question is what action will the user use to initiate this

so will the user click a button on your application to execute this ?
and what criteria will be enetered into the textboxes on the page  ?
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

whorsfallAuthor Commented:

Um I actually my c# app will be a simple winforms app that will generate the text to go into the input field.

Thanks ward
kaufmed 👽Commented:
I suggest using WatiN. I believe it was designed with unit testing in mind, but I've used it to automate IE for some of our internal applications. It is even flexible enough to allow you to search for inputs that don't have names or ids, if you so happen to have such.

There is also Selenium Web Driver which does the same thing. I haven't used it myself, but from what I've heard it sounds just a tad more involved to work with than WatiN is.

You can probably get by just using the WebBrowser control in WinForms. I cannot immediately recall how much control you have over the page in WB, but I know that you can execute Javascript against the page, so maybe that would be good enough.
whorsfallAuthor Commented:
Actually I wanted to bring up ie as a seperate app. As opposed having in on the web form and would like to keep it all native c# code.

But is JavaScript the best way Then?

Your request is not terribly complex, but there are some nuances that can cause some headaches.

The *easiest* method is to simply create a web browser in C# (lots of examples on the web - cut/paste).  Or if it doesn't have to be visual, just create a web service that creates a web call to the specified page.

once you are pulling the code into a session you can grab the objects via javascript and fill them and then submit the onclick event.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.